kotlinx / ast

Generic AST parsing library for kotlin multiplatform
Apache License 2.0
325 stars 23 forks source link

Argument with unary prefix is incomplete in summary AST #70

Closed henrikbarium closed 2 years ago

henrikbarium commented 2 years ago

If I run:

KotlinGrammarAntlrKotlinParser.parseKotlinFile(AstSource.String("source", "val b = f(!thisIsNotAvailable)"))

Then !thisIsNotAvailable is represented in the raw AST as a prefixUnaryExpression with a unaryPrefix (!) and postfixUnaryExpression (thisIsNotAvailable).

When i look at the corresponding summary AST, there is a KlassDeclaration with keyword argument supposedly representing !thisIsNotAvailable. However, looking at the argument's expression shows only a unaryPrefix node for the ! but no node for the identifier thisIsNotAvailable. If I look at the attached raw AST, the identifier is still there as expected.

Unless I'm missing something, I guess this is a bug.

henrikbarium commented 2 years ago

Unless I'm completely confused at the moment and doing something stupid, it seems to apply to more types of expressions when used as function arguments.

I get the same behavior for:

val s = f("a" + "b") // see only the +, not the string literals
val o = f(this ?: that) // does not see this/that or even an elvis operator literal
drieks commented 2 years ago

Hi @henrikbarium, this library can parse only the code outline, the content of functions are not implemented. I close this ticket as a duplicate of #69 and #21, I hope this is fine for you.