You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
john.michael.hall commented on 2018-03-22T19:46:50Z
Structs have opAssign defined by default. Alias this only forwards undefined lookups. Below is a workaround.
import std.stdio : writeln;
struct Base{
void opAssign(T)(T x){
writeln("assigning : ",x);
}
}
struct Derived{
Base parent;
alias parent this;
void opAssign(T)(T x){ parent = x;}
}
void main()
{
Base a;
a = 10; //ok
Derived b;
b = 20; //Error
}
schveiguy (@schveiguy) commented on 2020-09-04T12:14:51Z
Ran into this today.
If the compiler is going to generate an opAssign, it should generate one that forwards to the alias-this member. It should be something equivalent to adding the following overload to the existing generated opAssign:
auto ref opAssign(T)(auto ref T val) if (!is(T == typeof(this)) && __traits(compiles, aliasThisMember = val))
{
aliasThisMember = val;
}
BTW, thanks for the workaround. For a wrapped single alias-this member, it works perfectly.
SrMordred reported this on 2016-08-24T13:14:11Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=16426
CC List
Description
import std.stdio; struct Base{ void opAssign(T)(T x){ writeln("assigning : ",x); } } struct Derived{ Base parent; alias parent this; } void main() { Base a; a = 10; //ok Derived b; b = 20; //Error } Output: Error: function f937.Derived.opAssign (Derived p) is not callable using argument types (int)The text was updated successfully, but these errors were encountered: