Nullable types are not parsed correctly
xgouchet opened this issue · 4 comments
xgouchet commented
I'm parsing the following Kotlin code kotlinx.ast
and the KotlinGrammarAntlrKotlinParser
. But weirdly, I have some nullable types which are not marked as nullable.
package foo.bar
class Spam {
fun doSomething(i: Int, s: String?, l : List<String>) {}
}
Here's what I get when printing the AST nodes
PackageHeader(foo.bar)
importList
KlassDeclaration(object Spam)
PackageHeader(foo.bar)
importList
KlassDeclaration(class Spam)
classBody
KlassDeclaration(fun doSomething)
KlassDeclaration(parameter i Int)
KlassDeclaration(parameter s String)
KlassDeclaration(parameter l List<String>)
I'm using version c35b50fa44
from JitPack :
implementation("com.github.kotlinx.ast:grammar-kotlin-parser-antlr-kotlin-jvm:c35b50fa44")
xgouchet commented
If I print the raw AST for the s: String?
parameter, I get this, so the raw AST does know that the type is nullable :
functionValueParameter
parameter
simpleIdentifier
Identifier >>>s<<< (DEFAULT_TOKEN_CHANNEL)
COLON >>>:<<< (DEFAULT_TOKEN_CHANNEL)
Inside_WS >>> <<< (HIDDEN)
type
nullableType
typeReference
userType
simpleUserType
simpleIdentifier
Identifier >>>String<<< (DEFAULT_TOKEN_CHANNEL)
quest
QUEST_NO_WS >>>?<<< (DEFAULT_TOKEN_CHANNEL)
drieks commented
Hi @xgouchet,
sorry for the late answer, I was very busy.. I will have a look, it should be easy to fix.
drieks commented
xgouchet commented
Looks all good to me :) Thanks a lot