https://kotlinlang.org logo
#compiler
Title
# compiler
j

Javier

08/03/2022, 11:09 PM
I am getting an empty list when I call
function.contextReceivers
where
function
is
KtNamedFunction
with Kotlin 1.7.10. Is there any way to get the list of context receivers?
Tried 1.7.20 beta and same issue
d

denis.zharkov

08/04/2022, 7:48 AM
It should not be empty in case the function has context receivers specified. Otherwise other part of the feature wouldn’t just work.
j

Javier

08/04/2022, 8:08 AM
The use case can be weird, it was a test for a formatter, maybe the problem is I need to enable context receivers in tests or something so (the tests are just strings assertions).
d

denis.zharkov

08/04/2022, 9:21 AM
maybe the problem is I need to enable context receivers in tests
For that, actually you don’t need to enable anything in the test I would assume, there are just no context receivers on the
function
, probably it’s the wrong instance or something like that
j

Javier

08/04/2022, 10:13 AM
not sure what I am doing wrong
d

denis.zharkov

08/04/2022, 10:16 AM
Probably it’s worth trying to debug what children the PSI node of
function
actually have Like does it have a
CONTEXT_RECEIVER_LIST
j

Javier

08/04/2022, 10:16 AM
I have tried adding other things like
<T>
and they are there
looks like they are not detected, if I add a
<T>
, it is appearing there too as third element
d

denis.zharkov

08/04/2022, 10:19 AM
Really strange. Then I would debug if we really parse it at
org.jetbrains.kotlin.parsing.KotlinParsing#parseContextReceiverList
j

Javier

08/04/2022, 10:20 AM
the debugger doesn't enter in that function
d

denis.zharkov

08/04/2022, 10:21 AM
But how does it behave at
parseTopLevelDeclaration
? At the
Copy code
if (at(CONTEXT_KEYWORD)) {
    parseContextReceiverList();
}
j

Javier

08/04/2022, 10:27 AM
the debugger doesn't even appear outside
if
🤔
I put a breakpoint in all of those lines
looks like the debugger doesn't work there
or it is not entering
d

denis.zharkov

08/04/2022, 10:33 AM
It’s really hard to tell, but it seems that you’ve got some semi-correct env where the parsing classes come from the outdated version of compiler or something like this 😞
j

Javier

08/04/2022, 10:34 AM
Not sure, I can push to a branch and share a repo for you
d

denis.zharkov

08/04/2022, 10:43 AM
Sorry, I’m not sure I will be able to dig into this issue deeper, soon. Only can suggest to somehow make sure that
org.jetbrains.kotlin.parsing.KotlinParsing
used at runtime is really up-to-date (i.e., it actually has
parseContextReceiverList
method) or somehow figure out how to debug it properly.
j

Javier

08/04/2022, 10:47 AM
the debugger is entering in the KotlinParsing class, but not in the
parseFile
method
yeah, there is something weird now
2 Views