zserio
zserio copied to clipboard
Improve identifier ambiguities in expressions
Currently, the following steps are taken to resolve identifiers in expressions:
- The identifier is looked up in local scope.
- If not found, the identifier is looked up in all visible symbols in package (currently only constants).
- If not found, the identifier is looked up in all visible types in package.
- If not found, the identifier is considered as a package identifier.
This brings the following problems, for example:
package test;
import constant.Language;
struct Item
{
uint16 param;
Language language;
uint32 value if language == Language.CPP; // error!
};
enum bit:2 Language
{
CPP = 0,
JAVA = 1,
PYTHON = 2,
JS = 3
};
During the resolution of expression Language.CPP
, the identifier 'Language' is found as visible symbol in package (import constant.Language
), hence expression Language.CPP
is wrong.
Another example:
package test;
const bool test = true;
struct Employee
{
string name;
uint16 salary if test.test; // error
};
During the resolution of expression test.test
, the first identifier test
is found as visible symbol in package (const bool test = true
), hence expression test.test
is wrong.
We should very carefully define the resolution order of identifiers in expressions. Beside of that, consider report ambiguity errors rather than wrong expressions.