D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12285 - Allow local symbols in alias parameter to non-static templates when both have same scope
Summary: Allow local symbols in alias parameter to non-static templates when both have...
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks: 12230
  Show dependency treegraph
 
Reported: 2014-03-02 07:02 UTC by Vladimir Panteleev
Modified: 2020-05-24 15:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2014-03-02 07:02:53 UTC
///////// test.d ////////
struct S
{
    int a, c;

    template toA(alias s)
    {
        void copy()
        {
            a = s;
        }
    }

    alias cToA = toA!c;
}

unittest
{
    S s;
    s.c = 42;
    s.cToA.copy();
    assert(s.a == 42);
}
/////////////////////////

Currently, this produces:

test.d(13): Error: template instance toA!(c) cannot use local 'c' as parameter to non-global template toA(alias s)

Note that this restriction only applies to variables, but not methods, because of issue 12230. Fixing 12230 without merging this would surely break code (e.g. is std.regex, see set!setInvMask).
Comment 1 Vladimir Panteleev 2014-03-02 12:31:10 UTC
https://github.com/D-Programming-Language/dmd/pull/3345
Comment 2 basile-z 2020-05-24 15:28:09 UTC
works since 2.087.1.