Bug 21351 – When struct A is imported inside struct B, with(B) gets passed to A() constructor.
Status
RESOLVED
Resolution
MOVED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-10-30T13:09:32Z
Last change time
2020-11-01T06:13:09Z
Keywords
industry
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2020-10-30T13:09:32Z
Consider these three files:
--- a.d
struct A { int value; }
--- b.d
struct B { import a : A; }
--- test.d
void main() { with (B()) A(0); }
DMD will say:
test.d(5): Error: cannot implicitly convert expression __withSym of type B* to int
Despite B() not being necessary or allowed for A().
Comment #1 by boris2.9 — 2020-10-31T12:11:23Z
This code should error about 'A' not being found in 'B' because imports are private by default.
For example:
void main() { B().A(0); } // prints: 'Error: no property A for type b.B'
or using a type instead of a symbol in 'with' statement:
void main() { with (B) A(0); } // same error
You can make it work by changing:
struct B { import a : A; }
to:
struct B { public import a : A; }
I will try to fix the error but I'm not sure whether to change the bug subject or file a new one.