Bug 16305 – opCat opCatAssign priority bug

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2016-07-20T19:52:00Z
Last change time
2016-07-20T20:53:25Z
Assigned to
nobody
Creator
kapblc

Comments

Comment #0 by kapblc — 2016-07-20T19:52:17Z
import std.stdio; void main(){ int[] m = [1,2,3]; m = m ~ 4 ~ 5; // ok m ~= 4 ~ 5; // not work }
Comment #1 by lodovico — 2016-07-20T20:11:04Z
(In reply to Danila Letunovskiy from comment #0) > import std.stdio; > > void main(){ > int[] m = [1,2,3]; > > m = m ~ 4 ~ 5; // ok > > m ~= 4 ~ 5; // not work > } It works as intended. binary ops have precedence over assignment ops, so your last expression is equivalent to m ~= (4 ~ 5); And (4 ~ 5) does not make sense, because ~ is defined when at least one operand is an array. What you want is one of these two (probably the first): (m ~= 4) ~= 5; m ~= [4] ~ 5;
Comment #2 by schveiguy — 2016-07-20T20:53:25Z
Lodovico is correct.