Issue 20072 - [2.087.0] Mixin templates: no property `somevar` for type `some.Type`, did you mean `some.Type.__anonymous.somevar`?
Summary: [2.087.0] Mixin templates: no property `somevar` for type `some.Type`, did yo...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 blocker
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-22 14:54 UTC by Ethan Watson
Modified: 2019-08-01 11:54 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 Ethan Watson 2019-07-22 14:54:31 UTC
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 Ethan Watson 2019-07-22 15:15:30 UTC
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 Ethan Watson 2019-07-23 18:28:11 UTC
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 Simen Kjaeraas 2019-07-23 19:24:41 UTC
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 ZombineDev 2019-07-24 06:48:21 UTC
Fixed by https://github.com/dlang/dmd/pull/10214
Comment 5 Ethan Watson 2019-08-01 11:54:57 UTC
Confirmed that this fixes my static foreach woes