Bug 13435 – Strange error if struct is a class member and opAssign applied
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-07T09:22:57Z
Last change time
2018-04-19T07:14:56Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Temtaime
Comments
Comment #0 by temtaime — 2014-09-07T09:22:57Z
import std.stdio;
struct S(T) {
void opAssign(T[] arg) {}
}
class B {
this(int[] d) {
S!int c;
//_a = d; // Error: cannot implicitly convert expression (d) of type int[] to S!int
c = d; // compiles OK
}
S!int _a;
}
void main() {
}
Comment #1 by temtaime — 2014-09-07T09:29:08Z
If this(T[] arg) {} is overloaded then error is gone. But it's strange in any case.
Comment #2 by k.hara.pg — 2014-09-07T10:26:06Z
(In reply to Temtaime from comment #1)
> If this(T[] arg) {} is overloaded then error is gone. But it's strange in
> any case.
A first field assignment inside constructor is implicitly translated to the field initializing. So the line `_a = d;` does not see opAssign.
http://dlang.org/class#field-init
But, I agree the diagnostic message is not good to understand what's the problem.
Comment #3 by razvan.nitu1305 — 2018-04-18T11:17:26Z