Question

When trying to initialize a Type to \int(), as found in http://tutor.rascal-mpl.org/Rascal/Libraries/analysis/m3/Core/modifiers/modifiers.html#/Rascal/Libraries/lang/java/m3/AST/Declaration/Declaration.html , rascal throws an error saying "Expected Type, but got TypeSymbol".

This is the code I used:

Type inttype = \int();

What is the proper way to initialize a Type variable to \int()?

Was it helpful?

Solution

To solve the problem you can write:

Type myIntType = Type::\int();

More explanation follows. The \int() constructor is defined at least twice in different places:

  • In the abstract syntax tree definition of Java types that are used in Declarations. It is the representation of the word int in source code.
  • In the TypeSymbol definition in java::lang::m3::Core. There \int() represents a symbolic type.

They have the same name because they point to the same concept, but in different representations. The first is just used for a direct representation of source code, the second is used for its abstract symbolic interpretation.

To distinguish between the two representations you should either import the module that defines the AST nodes, or import the module that defines the TypeSymbols. If you happen to have both imported, you should choose a representation explicitly:

Type myIntType = Type::\int(); TypeSymbol mySymbol = TypeSymbol::\int();

So to finally explain the error message, the system chose the second kind of \int()` in TypeSymbol to build a value, and you tried to assigned it to a variable of the first kind.

OTHER TIPS

\int() is a TypeSymbol, I think you're looking for

Type inttype = int();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top