D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21351 - When struct A is imported inside struct B, with(B) gets passed to A() constructor.
Summary: When struct A is imported inside struct B, with(B) gets passed to A() constru...
Status: RESOLVED MOVED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: industry
Depends on:
Blocks:
 
Reported: 2020-10-30 13:09 UTC by FeepingCreature
Modified: 2020-11-01 06:13 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2020-10-30 13:09:32 UTC
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 Boris Carvajal 2020-10-31 12:11:23 UTC
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.
Comment 2 Boris Carvajal 2020-11-01 06:13:09 UTC
I'm closing this in favor of issue 21353.