D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3858 - mixin attribute is ignored
Summary: mixin attribute is ignored
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2010-02-26 14:46 UTC by Jerry Quinn
Modified: 2021-04-15 14:01 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 Jerry Quinn 2010-02-26 14:46:29 UTC
class C {
  mixin("private:");
  void f() {}
  invariant() { f(); }
}

fails to compile.  The private attribute is probably not being inserted early enough during the parsing process.
Comment 1 Jerry Quinn 2010-03-13 11:41:54 UTC
This is another example of the same phenomenon.  This should fail to compile, but succeeds.

class F {
  mixin("static:");
  void foo() { throw this; }
}
Comment 2 basile-z 2019-04-25 14:48:36 UTC
This is complicated to fix properly. During CompileDeclaration semantic, DMD parses a token (so the protection let's say), the colon and then a block that's empty (since it's already there). 

A kind of flag must be put to detect this particular case and then after the CompileDeclaration semantic, if the flag is set, all the following declarations must be pulled in the new attribute.

The most simple at first glance would be to disallow MixinDeclaration to finish with an AttributeSpecifier (the form that uses a colon)
Comment 3 RazvanN 2019-11-06 15:13:09 UTC
Maybe a solution would be to parse string mixins at parse time and simply glue the resulting AST to the main AST.
Comment 4 Adam D. Ruppe 2021-04-15 14:01:13 UTC
I'm gonna go ahead and close this because it isn't really a bug.

mixins always work on complete AST nodes. They don't paste in code that modifies future things, it is all self-contained.

So you should think of the mixin stuff to be wrapped in {}. Sort of, obviously that's not always literally true but it illustrates the scope limitation.

So mixin("private:") is like mixin("{private:}").

that is, it does exactly what it is supposed to do: apply private to the end of the current declaration block... but the current declaration block inside the mixin ends where the mixin ends. Meaning it is just a do-nothing thing, which is perfectly legal!