-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context receivers give ParseError
#397
Comments
Adding this to @Test
fun `Context receivers are parsed correctly`() {
val code = """
|class A {
| context(String)
| fun test() {}
|}
|""".trimMargin().trimMargin()
val file = Parser.parse(code)
val tokenizer = Tokenizer(code, file)
file.accept(tokenizer)
assertThat(tokenizer.toks.map { it.originalText })
.containsExactly("class", " ", "A", " ", "{", "\n", " ", "context", "(", "String", ")", "\n", " ", "fun", " ", "test", "(", ")", " ", "{", "}", "\n", "}")
.inOrder()
assertThat(tokenizer.toks.map { it.index })
.containsExactly(0, -1, 1, -1, 2, -1, -1, 3, 4, 5, 6, -1, -1, 7, -1, 8, 9, 10, -1, 11, 12, -1, 13)
.inOrder()
} Changing However, this is where my knowledge ends 😅 Adding this to @Test
fun `context receivers`() =
assertFormatted(
"""
|class A {
| context(String)
| fun test() {}
|}
|"""
.trimMargin()) |
@bddckr I don't think #314 indicates that ktfmt used to support context receivers. Rather, any situations in which they work right now are incidental. In that issue, they're parsed but not formatted correctly. In your example, they're not parsed at all. Normally I'd close this as a duplicate, but the fact that this causes a crash (instead of just bad formatting) means we should consider a mitigation at least (if a full fix is hard). @strulovich has there been any investigation into this? |
Using
com.diffplug.spotless:spotless-plugin-gradle:6.18.0
configured to usektfmt().kotlinlangStyle()
fails to parse usage of context receivers.Minimum example:
leads to
According to the context receivers proposal here, the earliest Kotlin release that supports them is
1.6.20-M1
. However, ktfmt seems to be using1.6.10
as seen here. Am I correct to assume that that's the issue?#314 seems related, but according to the comments in that issue, ktfmt at one point worked when using context receivers. This issue here instead explains that ktfmt is basically crashing due to an issue parsing the source code.
The text was updated successfully, but these errors were encountered: