Closed lppedd closed 7 months ago
It looks good, but in general it is very hard for me to review changes to the template. Perhaps having a bit more tests would be useful here
@ftomassetti in this case I've pretty much replicated what the Swift template does.
But yes, if we can, having some other tests would be better. At some point we'll get there.
FYI, I'm not sure if it's a correct patch. If I applies it, some tests from ANTLR 5 repository starts to fail (NullPointerException
). I fixed the problem by adding @Suppress("UNSAFE_CALL")
to private fun <r.name>_sempred(_localctx: <r.ctxType>?, predIndex: Int): Boolean
. Using suppressing is also not the best solution, but at least it works (it could be fixed later).
That's strange. Theoretically you should never have a null context at that point.
I'll have a better look after porting back the template fixes.
I recommend trying out tests in the ANTLR 5 runtime (my branch regarding integration until it's merged) 😊
I'll try. It's just strange that it happens with Kotlin and not with Swift, I've used the exact same nullabilities.
@KvanTTT managed to reproduce also with a MySQL grammar. I'll check what's happening.
@KvanTTT so I was wrong, there are situations where a null
context is possible.
In case of the MySQL grammar, a LexerCustomAction
is executed, which has an execute
method like:
override fun execute(lexer: Lexer): Unit =
lexer.action(null, ruleIndex, actionIndex)
The lexer in that case is MySQLLexer
, which overrides the action
method:
override fun action(_localctx: RuleContext?, ruleIndex: Int, actionIndex: Int) {
when (ruleIndex) {
21 -> LOGICAL_OR_OPERATOR_action(_localctx as RuleContext, actionIndex)
70 -> INT_NUMBER_action(_localctx as RuleContext, actionIndex) // <-- NPE
...
Yes, and such situations are also possible in testsuite.
Fixes: #157