After a thorough look through kotlin grammar I can’t wrap my head around this part of the language.
As far as my understanding goes, everything about accessing data from object goes through postfixUnaryExpression
then postfixUnarySuffix
and after that everything that starts with dot is processed by navigationSuffix
.
But navigationSuffix
can only by converted into .identfier
or .parenthesizedExpression
First of which doesn’t allow parenthesis and thus calling methods and second doesn’t make any sense to me at all.
How does a.(something)
makes sense? And how does it parse a.foo()
?
Are you sure that parenthesizedExpression
doesn’t contain an identifier itself?
You can check for yourself
It always starts and ends with a parenthese, which doesn’t allow for a.foo()
I’d expect there to be callSuffix
insted of parenthesizedExpression
This looks like a typo in grammar or something around those lines
expression
|
disjunction
|
conjunction
|
equality
|
comparison
|
genericCallLikeComparison
|
infixOperation callSuffix
| \
elvisExpression valueArguments
| |
infixFunctionCall '(' ')'
|
rangeExpression
|
additiveExpression
|
multiplicativeExpression
|
asExpression
|
prefixUnaryExpression
|
postfixUnaryExpression
|
primaryExpression postfixUnarySuffix
| |
simpleIdentifier navigationSuffix
| |
Identifier memberAccessOperator simpleIdentifier
| | |
'a' '.' Identifier
|
'foo'
Cool! Thanks
I missed that option
Do you have any examples of navigationSuffix
going to parenthesizedExpression
?
fun getMember() : Int.() -> Int = { this + 1 }
fun main() {
println(42.(getMember())())
}