Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum variants in modules not recognized without importing type in main module #154

Open
noloerino opened this issue Feb 11, 2022 · 1 comment

Comments

@noloerino
Copy link

If an enum variant is referenced within a next block or procedure within a module, a "Type error ... Unknown identifier [variant name]" error is reported erroneously if the enum type is not imported in main.

Minimal example

module m1 {
    type op_t = enum { ADD, SUB };
    type non_enum_t = integer;

    // var g_inst : op_t; // Uncommenting this line fixes the issue

    init { } 

    next {
        var inst : op_t;
        var n : non_enum_t;
        inst = ADD;
        n = 100;
    }   
}

module main {
    // type op_t = m1.op_t; // Uncommenting this line ALSO fixes the issue

    instance i : m1 (); 
        
    next {
        next (i);
    }

    control { } 
}

Running this file causes the error on latest master (e244310). The workaround, as suggested by the comments in the above example, is to import the enum type in the main module being run.

More details

  • The type error is still reported if the enum type is defined in another external module (for example, if type op_t were defined in some other module m0, and imported in m1).
  • Declaring a global variable in m1 with the type of the enum in question also fixes the error somehow (see code example above).
@polgreen
Copy link
Contributor

Ok, this is definitely a bug, caused by having local variables in next that have types that are only in the submodule. I'll fix this.

btw there's not often much benefit to having local variables in uclid (as in, there's not usually much/any additional cost to having them be module level variables instead of local to the next block)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants