[Issue 16305] opCat opCatAssign priority bug
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jul 20 13:11:04 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16305
Lodovico Giaretta <lodovico at giaretart.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lodovico at giaretart.net
--- Comment #1 from Lodovico Giaretta <lodovico at giaretart.net> ---
(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;
--
More information about the Digitalmars-d-bugs
mailing list