Error compiling match(_)case(_)
Closed this issue · 5 comments
Compiler error in identifierResolution.grace on line 244. It is apparently calling method uid on "done". This was raised by compiling the same code that generated the last compiler error.
Error message:
Internal compiler error at line 0 of native code. NoSuchMethod: no method uid on done (defined in module built-in library).
NoSuchMethod: no method uid on done (defined in module built-in library).
raised from serializeVariable(_)withName(_)in(_) at line 244 of identifierresolution
requested from block.apply(_,_) at line 181 of identifierresolution
requested from block.apply(_,_) at line 324 of scope
requested from nameDictionary(_).keysAndValuesDo(_) at line 1247 of collections
requested from objectScope.localAndReusedNamesAndValuesDo(_)filteringOut(_) at line 322 of scope
requested from objectScope.localAndReusedNamesAndValuesDo(_) at line 765 of scope
requested from block.apply at line 1 of identifierresolution
requested from while(_)do(_) at line 113 of intrinsic
requested from generateGctForModule(_) at line 173 of identifierresolution
requested from writeGctForModule(_) at line 125 of identifierresolution
requested from compile(_,_,_,_) at line 1717 of genjs
requested from block.apply at line 82 of compiler
requested from compileInputFile at line 23 of compiler
Compilation terminated.
in "minigrace"
Please provide the code that generates this error
After lots of experimentation, here is pretty minimal code that generates the problem:
class pieceOn (colorNum: Number) {
def current: Number = match(colorNum)
case {1 -> 2}
case {2 -> 3}
case {3 -> 4}
case {4 -> 5}
}
The error goes away if you replace the "def" by "var". I suspect it is an initialization timing problem with match of the right hand side.
Here is the error message again:
Internal compiler error at line 0 of native code. NoSuchMethod: no method uid on done (defined in module built-in library).
NoSuchMethod: no method uid on done (defined in module built-in library).
raised from serializeVariable(_)withName(_)in(_) at line 244 of identifierresolution
requested from block.apply(_,_) at line 181 of identifierresolution
requested from block.apply(_,_) at line 324 of scope
requested from nameDictionary(_).keysAndValuesDo(_) at line 1247 of collections
requested from objectScope.localAndReusedNamesAndValuesDo(_)filteringOut(_) at line 322 of scope
requested from objectScope.localAndReusedNamesAndValuesDo(_) at line 765 of scope
requested from block.apply at line 1 of identifierresolution
requested from while(_)do(_) at line 113 of intrinsic
requested from generateGctForModule(_) at line 173 of identifierresolution
requested from writeGctForModule(_) at line 125 of identifierresolution
requested from compile(_,_,_,_) at line 1717 of genjs
requested from block.apply at line 82 of compiler
requested from compileInputFile at line 23 of compiler
Compilation terminated.
in "minigrace"
Thank you! Although it's nice to have minimal code that provokes the error, just linking to the file in a repo that contains any code that provokes the error is ok. Not having the code makes it impossible to debug.
This is not an initialization problem. It's a compiler bug arising when trying to construct the scope for current
. When current
is a var, no attempt is made to construct its scope, because the scope can be different after each assignment.