(core) Fix bug with renaming when a formula uses a local name for a user table.

Summary:
When a formula used a local variable referring to a user table (which is
a global name), e.g. `myvar = MyTable; myvar.lookupOne(...)`, renaming
logic mistakenly used the inferred name (`MyTable`) in places where the
actual variable name (`myvar`) should have been used.

Additionally, we should not rename local variables, even if they match a
global name.

This fixes both issues.

Test Plan: Added a test case that checks that local variables aren't renamed.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3846
This commit is contained in:
Dmitry S
2023-03-30 23:51:13 -04:00
parent d8a063284a
commit fb1332d529
2 changed files with 33 additions and 3 deletions

View File

@@ -395,3 +395,27 @@ class TestRenames2(test_engine.EngineTestCase):
self.assertTableData("People", cols="subset", data=self.people_data)
self.assertTableData("Games", cols="subset", data=self.games_data)
def test_renames_i(self):
# Rename when using a local variable referring to a user table.
# Test also that a local variable that happens to match a global name is unaffected by renames.
self.modify_column("Games", "winner", formula=(
"myvar = Entries\n"
"People = Entries\n"
"myvar.lookupOne(game=$id, rank=1).person\n"
"People.lookupOne(game=$id, rank=1).person\n"
))
self.apply_user_action(["RenameColumn", "Entries", "game", "juego"])
self.apply_user_action(["RenameTable", "People", "Persons"])
# Check that renames worked.
new_col = self.engine.docmodel.columns.lookupOne(tableId='Games', colId='winner')
self.assertEqual(new_col.formula, (
"myvar = Entries\n"
"People = Entries\n"
"myvar.lookupOne(juego=$id, rank=1).person\n"
"People.lookupOne(juego=$id, rank=1).person\n"
))
self.assertTableData("Persons", cols="subset", data=self.people_data)
self.assertTableData("Games", cols="subset", data=self.games_data)