zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Improve identifier ambiguities in expressions

Open mikir opened this issue 4 years ago • 0 comments

Currently, the following steps are taken to resolve identifiers in expressions:

  1. The identifier is looked up in local scope.
  2. If not found, the identifier is looked up in all visible symbols in package (currently only constants).
  3. If not found, the identifier is looked up in all visible types in package.
  4. 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.

mikir avatar Apr 22 '20 08:04 mikir