1

I have my IntelliJ editor configured to reformat lines that are longer than 120. It does some lines no problem. For example

val myVar = function(param1, param2, ......... paramN)

transitions to the following automatically without issue (running reformat)

val myVar = function(
   param1, param2, ......... paramN
)

However, it seems to have trouble with long strings. It should be equivalent to change

fail("I am a really long string ..... greater than 120 characters")

to

    fail("I am a really long string "
    + "..... greater than 120 characters")

Why won't the editor do this for me? This is a Kotlin project.

stk1234
  • 1,036
  • 3
  • 12
  • 29
  • Because this will generate a slightly different bytecode (unless the whole string is a compile-time constant and compiler has an optimization for it)? – Михаил Нафталь Aug 16 '21 at 18:29
  • @МихаилНафталь As far as I can see, some points are clearly impossible to wrap at (e.g. within keywords or identifiers or string template expansions), or are safe and would have no effect on the meaning or resulting bytecode (e.g. the examples in this question).  The reformatter is smart enough to avoid the unsafe points outside string literals, so I don't see why it wouldn't be able to avoid the unsafe points _within_ them too. – gidds Aug 16 '21 at 20:59
  • @gidds The thing is "safe points" inside string literals are not mentioned in the language specification. They are implementation details of the compiler. Moreover, Kotlin has several compilation targets (hence several compiler backends, which could or could not optimize concat of compile-time string constants). Probably, IDE could do this when all target platforms will share the same IR compiler backend, which [has this optimization](https://github.com/JetBrains/kotlin/blob/master/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/optimizations/FoldConstantLowering.kt). – Михаил Нафталь Aug 17 '21 at 09:57
  • Please, file an issue - https://kotl.in/issue – vanyochek Aug 24 '21 at 10:27

0 Answers0