Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Auto-formatting redundant curly braces in specific string template fails to compile #883

Closed
axemorgan opened this issue Sep 1, 2020 · 3 comments · Fixed by #888
Closed
Labels

Comments

@axemorgan
Copy link

Expected Behavior

After formatting the following code (which does compile), the result should also compile.
Input (Bug.kt):

fun main() {
    println("This is: ${null}")
}

ktlint output:

fun main() {
    println("This is: $null")
}

Observed Behavior

Compilation of the formatted code fails with this error:

Bug.kt:2:25: error: keyword cannot be used as a reference

Steps to Reproduce

  1. Format the input file using ktlint -F Bug.kt
  2. Compile it: kotlinc Bug.kt
  3. Compilation fails

Your Environment

  • ktlint: 0.37.2
  • kotlinc: kotlinc-jvm 1.4.0 (JRE 13.0.1+9)

Note: I don't think it's particularly useful to use ${null} in a string template, I just ran across this while formatting a large project. 😅

@romtsn romtsn added the bug label Sep 2, 2020
@romtsn
Copy link
Collaborator

romtsn commented Sep 2, 2020

I'm wondering if there are any other keywords that can be used in the string template?

@axemorgan
Copy link
Author

I tried a few keywords from this list, and the same problem occurs for true and false. Those two and null seem to be the only keywords I can find that are valid expressions by themselves, otherwise "${keyword}" isn't valid code.

@romtsn
Copy link
Collaborator

romtsn commented Sep 2, 2020

Thanks for checking 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants