Overwriting type inference rule for constant expression

Hey,

As in MPS-15877 mentioned there is some difference between Java and baselanguage concerning the type of integer literal expressions. While in Java the type of this constant expressions depends on their values in baselanguage it is always int. The author of the issue suggests to change the subtyping rule of IntegerConstant. But this will not handle the expression types correctly in all cases. Try to compile this examples with javac
byte b1 = 126 + 1;
byte b2 = 127 + 1;
final byte NUM = 127;
byte b3 = NUM + 1;

you will recognize type errors in line 2 and 4. Java seems to fold constant expressions before resolve their types.
This behavior really should be added to baselanguage. I would like to have a similar thing in my language, too. But I don't know how to specify such a type of a constant expression. There must be an inference rule which overwrites other rules if the expression isCompileTimeConstant. The type can then be inferred by the result of the getCompileTimeConstantValue method.
Is it somehow possible to describe such a thing with MPS at the moment?

Please sign in to leave a comment.