Search code examples
rascal

Variable unknown when not initialized in the declaration


I ran into this today, and I was wondering if something is going wrong here.

module example

public rel[str file, AstNode namespace] relFileNamespace;
public void InitGlobals()
{
    relFileNamespace = {};
}

Then in the console:

rascal>import example;
ok

rascal>InitGlobals();
ok

rascal>relFileNamespace
|stdin:///|(0,13,<1,0>,<1,13>): Undeclared variable, function or constructor: relFileNamespace

If I declare it like this it does work.

public rel[str file, AstNode namespace] relFileNamespace = {};

So the question is, why does it have to be initialized in the declaration?


Solution

    • Rascal does not allow uninitialized variables at all, but it should complain about "uninitialized" in that case, not "undeclared"
    • It is not finding your variable. Could you try adding "example::" before dereferencing?