Bug 8785 – feature request: static mixin

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-08T12:43:25Z
Last change time
2024-12-13T18:01:34Z
Assigned to
No Owner
Creator
luka8088
Moved to GitHub: dmd#18472 →

Comments

Comment #0 by luka8088 — 2012-10-08T12:43:25Z
Currently, there is no way of encapsulating mixin templates as static keyword has no effect. import std.stdio; mixin template myTemplate () { void fn () { writeln("myTemplate"); } } struct myStruct { static mixin myTemplate t1; // static keyword has no effect } void main () { myStruct s1; s1.t1.fn(); // myTemplate s1.fn(); // myTemplate } I would kindly request that static keyword encapsulates the template members so that s1.fn is not directly accessible but rather only as s1.t1.fn One hack proposal was to use static struct t1 { mixin myTemplate; } but that turned out to be a bed idea because in that case mixin code can't use this to access myStruct
Comment #1 by andrej.mitrovich — 2013-01-26T15:16:21Z
What this would basically do is introduce namespaces into the language, as 't1' would be some kind of pseudo-type which has access to its parent, but it itself wouldn't be a template (since it doesn't require !()), and it wouldn't be an aggregate. Not that there's anything wrong with that. :) Anyway for the longest time I actually thought "mixin myTemplate t1" means the symbols are only accessible through "t1", but the spec does say it's only used for disambiguating so I was wrong.
Comment #2 by luka8088 — 2013-01-27T12:21:19Z
(In reply to comment #1) > What this would basically do is introduce namespaces into the language, as 't1' > would be some kind of pseudo-type which has access to its parent, but it itself > wouldn't be a template (since it doesn't require !()), and it wouldn't be an > aggregate. > > Not that there's anything wrong with that. :) > > Anyway for the longest time I actually thought "mixin myTemplate t1" means the > symbols are only accessible through "t1", but the spec does say it's only used > for disambiguating so I was wrong. I also thought this way, until I read the docs properly. It would be useful in some cases to have both behaviors. "static" is proposed because it is already used with imports in this way - "import" vs "static import". Maybe "static" is not the best keyword/solution for this case but it is the first solution that came to mind.
Comment #3 by robert.schadek — 2024-12-13T18:01:34Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18472 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB