February 05 [Issue 24371] New: String array concatenation does not respect operator precedence | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24371 Issue ID: 24371 Summary: String array concatenation does not respect operator precedence Product: D Version: D2 Hardware: x86 OS: Linux Status: NEW Severity: regression Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: dechcaudron+issues.dlang@pm.me Hi, something odd happens when you mix parenthesis and variables to concatenate strings and string arrays. See code below: ``` unittest { // All works well with literals assert("b" ~ "c" == "bc"); assert(["a"] ~ "b" == ["a", "b"]); assert(["a"] ~ ("b" ~ "c") == ["a", "bc"]); // Things work well as long as you only reference one variable auto strArr = ["a"]; assert(strArr ~ ("b" ~ "c") == ["a", "bc"]); auto str = "c"; assert(["a"] ~ ("b" ~ str) == ["a", "bc"]); // Things stop working when both operands are variables // This should not pass assert(strArr ~ ("b" ~ str) == ["a", "b", "c"]); // This should not fail assert(strArr ~ ("b" ~ str) == ["a", "bc"]); } ``` When the issue is reproduced, the compiler behaves as if the parenthesis were not there and appends each individual string to the string array. This code used to work years ago (unfortunately I cannot remember the DMD version I was using back then, but it was 2021). I don't know if it also happens in systems other than Linux. -- |
Copyright © 1999-2021 by the D Language Foundation