https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

martmists

05/28/2022, 4:44 PM
In this snippet, sequence{} knows its in the
parens
rule if you check prop.name in getValue or provideDelegate, but is there a way the resolve() call could get access to this information somehow? I checked the stack trace and couldn't really find anything that could give this information
e

ephemient

05/28/2022, 4:48 PM
what is
sequence
? that isn't the standard library's
m

martmists

05/28/2022, 4:48 PM
This is a custom function in my code, it uses the delegate's name in case of an error and I want to be able to access it in the resolve() calls as well
Turns out you can find the name of the delegate when it's not inlined (sequence being marked as inline) by looking at the class name (in my case
DummyParser$root$2
) but when inlined this is not available (same call:
DummyParser$special$$inlined$sequence$1
)
j

Joffrey

05/28/2022, 4:53 PM
Maybe that would be a case for context receivers.
sequence
could provide this information to nested
resolve
calls
But you could also pass it to
resolve
as a regular argument of course
e

ephemient

05/28/2022, 4:55 PM
even without context receivers, if you write
fun sequence(block: SequenceScope.() -> Unit)
where
interface SequenceScope { fun Char.resolve() }
, then
resolve
can have access to it as long as you provide it in
SequenceScope
j

Joffrey

05/28/2022, 4:56 PM
Yes, I was assuming the object provided by
sequence
didn't know about resolve. Another option, if this is just for error handling, would be to add a try/catch inside the implementation of
sequence
that wraps exceptions into a higher level one with additional debug information. But that option might not always be possible/suitable depending on how
sequence
runs its lambda