Bug 24371 – [REG 2.104] String array concatenation does not respect operator precedence

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2024-02-05T15:50:31Z
Last change time
2024-03-15T08:20:40Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
Dechcaudron

Comments

Comment #0 by dechcaudron+issues.dlang — 2024-02-05T15:50:31Z
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.
Comment #1 by ag0aep6g — 2024-02-05T18:31:31Z
Fails since 2.104, according to run.dlang.org.
Comment #2 by tim.dlang — 2024-02-09T17:12:58Z
It seems to fail since this PR: https://github.com/dlang/dmd/pull/14550
Comment #3 by dlang-bot — 2024-02-19T17:53:50Z
@teodutu updated dlang/dmd pull request #16204 "Fix Issue 24371 - String array concatenation does not respect operator precedence" fixing this issue: - Fix Bugzilla Issue 24371 - String array concatenation does not respect operator precedence Rethink lowering logic to account for parentheses and operator associativity. Signed-off-by: Teodor Dutu <[email protected]> https://github.com/dlang/dmd/pull/16204
Comment #4 by dlang-bot — 2024-02-20T12:40:53Z
dlang/dmd pull request #16204 "Fix Issue 24371 - String array concatenation does not respect operator precedence" was merged into stable: - 0e2a7f16a15ae3705e7791448165d8c9f789b942 by Teodor Dutu: Fix Bugzilla Issue 24371 - String array concatenation does not respect operator precedence Rethink lowering logic to account for parentheses and operator associativity. Signed-off-by: Teodor Dutu <[email protected]> https://github.com/dlang/dmd/pull/16204
Comment #5 by dlang-bot — 2024-03-01T23:56:59Z
dlang/dmd pull request #16276 "merge stable" was merged into master: - 2423b9379841cda4d1f6f5146a05dc5820225a7b by Teodor Dutu: Fix Bugzilla Issue 24371 - String array concatenation does not respect operator precedence Rethink lowering logic to account for parentheses and operator associativity. Signed-off-by: Teodor Dutu <[email protected]> https://github.com/dlang/dmd/pull/16276
Comment #6 by dechcaudron+issues.dlang — 2024-03-15T08:20:40Z
Thanks for fixing folks!