Bug 9367 – private in mixin template

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-22T03:00:53Z
Last change time
2019-08-29T17:37:06Z
Assigned to
No Owner
Creator
luka8088

Comments

Comment #0 by luka8088 — 2013-01-22T03:00:53Z
Upgrading to D v2.061 broke my code so I investigated and found inconsistent behavior. The following example compiled in D v2.060: // main.d import foo; void main () { mixin m m1; } // foo.d module foo; private struct s { int i; } mixin template m () { s s1; } // foo.d(9): Error: module main foo.s is private So I am not sure if this is a bug or was it a bug before, and there is actually no any documentation for this specific case (that I could find). It only says "Unlike a template instantiation, a template mixin's body is evaluated within the scope where the mixin appears, not where the template declaration is defined. It is analogous to cutting and pasting the body of the template into the location of the mixin." so it could be understood that mixin template can only see symbols from a scope that it is included in. On the other hand, if that is the expected behavior, then the following code should not compile (at least I think): // main.d import foo; void main () { mixin c.m m1; } // foo.d module foo; class b { private struct s { int i; } } class c { mixin template m () { b.s s1; } } Anyway, I think that the expected behavior in this cases should be better documented.
Comment #1 by pro.mathias.lang — 2019-08-29T17:37:06Z
Bug solved: The first case should not have compiled, and the second case does not compile anymore.