Bug 20072 – [2.087.0] Mixin templates: no property `somevar` for type `some.Type`, did you mean `some.Type.__anonymous.somevar`?
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-07-22T14:54:31Z
Last change time
2019-08-01T11:54:57Z
Assigned to
No Owner
Creator
Ethan Watson
Comments
Comment #0 by gooberman — 2019-07-22T14:54:31Z
Regression from 2.086.1
I haven't been able to isolate a code example for this yet, but the basic flow is:
* some.Type declaration
* Mixin a template that defines somevar and a function
* Function calls a templated function that takes this as the templated parameter
* New function calls back expecting somevar to be there
* Error message occurs
Needless to say, pragma( msg, __traits( allMembers, some.Type ).stringof ) right before I try accessing that variable in the templated function shows the member right there in the member list.
If anyone can spot why that anonymous scope isn't being imported back in to the object without the code example, that'll save me hours trying to reproduce it in an isolated code example.
There's no way I can upgrade past 2.086.1 while this is broken.
Comment #1 by gooberman — 2019-07-22T15:15:30Z
Turned on deprecations as warnings in 2.086.1. Looks like this stuff has been broken for a while.
For example:
Deprecation: `smithy.editor.server.Server.__anonymous.m_registry` is not visible from module `smithy.editor.common.behaviors.registry`
It is mixed in to smithy.editor.server.Server with a template like this:
mixin template Registry()
{
package( smithy.editor ) SmithyObjectRegistry m_registry;
}
And just to make sure, the function that tries to access m_registry does something like this:
module smithy.editor.common.behaviors.registry;
package( smithy ) auto createImpl( ServerType, Params... )( ServerType server, Params params )
{
import std.traits : moduleName;
mixin( "import " ~ moduleName!ServerType ~ ";" );
// Rest of code follows here...
}
Basically, there's no way that m_registry shouldn't be visible at this point.
Comment #2 by gooberman — 2019-07-23T18:28:11Z
It's a static foreach problem.
For whatever reason, static foreach is inserting that __anonymous scope. And generic code cannot deal with it. __traits( parent ) errors for example.
Example code follows:
import std.meta : AliasSeq;
import std.traits : moduleName;
string generateFor( string objectName )()
{
return "struct " ~ objectName ~ "{ }";
}
alias StructNames = AliasSeq!( "StructOne", "StructTwo", "StructThree" );
static foreach( Name; StructNames )
{
mixin( generateFor!Name );
}
pragma( msg, moduleName!StructOne );
Comment #3 by simen.kjaras — 2019-07-23T19:24:41Z
Further reduction:
static foreach( Name; 0..1 )
mixin( "struct S { }" );
// Error: local scope __anonymous is not a variable
pragma(msg, __traits(parent, S));
Comment #4 by petar.p.kirov — 2019-07-24T06:48:21Z