Bug 11718 – [REG2.065a] Unintended mangled names conflict of nested template structs

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-10T11:48:00Z
Last change time
2013-12-18T15:38:58Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
timothee.cour2

Comments

Comment #0 by timothee.cour2 — 2013-12-10T11:48:34Z
$dmd_064_2_X -main -unittest -run main.d #ok $dmd -main -unittest -run main.d # Error: struct main.setfields!(A).setfields.Proxy!(true, a, null).Proxy failed semantic analysis --- auto setFields_aux(bool isRef,alias foo,string s,T...)(T args) { import std.array:split; import std.conv:to; enum namesCall=split(s,","); static assert(namesCall.length==T.length); static if(isRef){ enum foo2_name="foo"; } else{ auto foo2=foo; enum foo2_name="foo2"; } string getString() { string ret; foreach(i,vali ; namesCall){ ret~=foo2_name~`.`~vali~`=`~`args[`~i.to!string~`];`; } ret~=`return `~foo2_name~`;`; return ret; } mixin(getString()); } private struct Proxy (bool isRef,alias func, string parameters, Args ...) { private static string addParameter (string parameters, string newParameter) () { return parameters is null ? newParameter : parameters ~ "," ~ newParameter; } Args args; this(int dummy,Args args){ static if(Args.length) this.args=args; } auto opDispatch (string name, T) (T value) { return Proxy!(isRef,func, addParameter!(parameters, name), Args, T)(0,args, value); } auto opCall()() { return setFields_aux!(isRef,func, parameters)(args); } } auto setfields(T)(T a){ return Proxy!(true,a, null)(0); } auto setfields(T)(){ T a; return Proxy!(true,a, null)(0); } unittest{ struct A{ int x; float y=10; string z; } auto z1=A.init.setfields.z("a").x(3)(); auto z2=setfields!A.z("a").x(3)(); } ---
Comment #1 by nilsbossung — 2013-12-11T14:53:18Z
(In reply to comment #0) Reduced: --- cat > test1.d << code struct Proxy(alias a) {} auto setfields(int a) { Proxy!a p; return p; } auto setfields() { int a; Proxy!a p; return p; } code dmd -c test1.d --- test1.d(1): Error: struct test1.setfields.Proxy!(a).Proxy failed semantic analysis test1.d(10): Error: template instance test1.setfields.Proxy!(a) error instantiating --- And another, similar trigger: --- cat > test2.d << code mixin template M() { struct S {} } mixin M!(); mixin M!(); code dmd -c test2.d --- test2.d(3): Error: struct test2.M!().S failed semantic analysis test2.d(6): Error: mixin test2.M!() error instantiating ---
Comment #2 by k.hara.pg — 2013-12-11T23:56:29Z
Comment #3 by github-bugzilla — 2013-12-16T12:53:33Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/71b0fce3a4f2849e82c9ba9972a65a6fee59d42f fix Issue 11718 - Unintended mangled names conflict of nested template structs If a symbol has parent, the parent part of the mangled name should also be unique in each scopes. Function symbols can have same identifiers in scope, so their parameters part must be always encoded in their mangled name to distinguish overloads. When I fixed bug 9271, I had naturally expected that behavior. However sadly `mangle` function had had a bug. https://github.com/D-Programming-Language/dmd/commit/95183bfb5265af56d5f03cbfdc8b59d9a7c47789 Merge pull request #2953 from 9rnsr/fix11718 [REG2.065a] Issue 11718 - Unintended mangled names conflict of nested template structs
Comment #4 by nilsbossung — 2013-12-18T15:38:58Z
(In reply to comment #1) > And another, similar trigger: > --- > cat > test2.d << code > mixin template M() > { > struct S {} > } > mixin M!(); > mixin M!(); > code > dmd -c test2.d > --- > test2.d(3): Error: struct test2.M!().S failed semantic analysis > test2.d(6): Error: mixin test2.M!() error instantiating > --- Opened a new ticket for this: bug 11767