[BUG] Multiline operator concatenation is being ignored

I’m writing the code snippet from memory, so I apologize if it does not properly compile. As far as I remember I run multiple times into this odd issue. In my codebases I set a fixed line width of 100 characters and start wrapping code into next lines if it’s exceeded.
In that sense if I have multiple arrays or string literals which I would like to merge, I start moving the + concatenation operation into next lines. However this seems to be swallowed by the compiler.

Func(): string = {
  Result := "first line"
    + "\nsecond line"
    + "\nthrid line"
    # etc.
  return Result
}

As far as I remember scenarios like this always resulted into only the first value being added to the result.

Workarounds:

Func(): string = {
  Result := "first line" + "\nsecond line" + "\nthrid line" # etc.
  return Result
}

Func(): string = {
  var Result: string = "first line" 
  set Result += "\nsecond line" 
  set Result += "\nthrid line" 
  # etc.
  return Result
}

The first workaround might not always be suitable as it could easily exceed the previously mentioned line width.
This is a critical issue as it’s extremely easy to miss und totally unintuitive. Missing string parts is relatively harmless, but missing array elements can lead to unexpected program behavior and bugs.

Yep it’s strange considering that it works with if statements :

RotationMultiplier := if(1 > 0)
                      then true
                      else false

Also, did you try putting the ‘+’ operator at the end of the line like this ?

Func(): string = {
  Result := "first line" +
    "\nsecond line" +
    "\nthrid line"
    # etc.
  return Result
}

No I have not tried it, it might actually work if my assumption about operator inference is correct.

I guess the compiler treats the + as prefix operators instead correctly indicting those as wrapped infix operators.

In general I would say that prefix or suffix operators should not permit whitespaces between them and their values while infix operators should at least prefer whitespaces for readability.

+ something # raise an error (prefix)
+something # okay (prefix)

a + b # infix (preferred)
a+b # infix 

a
+
b # okay but harder to read

some_long_name
  + something_else # okay (infix)

cc @Conan_Reis

1 Like