D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18386 - mixin ... isn't a template error when used in new scope
Summary: mixin ... isn't a template error when used in new scope
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-06 22:30 UTC by tetyys
Modified: 2024-12-13 18:56 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 tetyys 2018-02-06 22:30:31 UTC
Compilation of this code:

import std.stdio;

void main() { }

class c {
        this() {
                enum string b(alias d)() {
                        return `writeln("a");`;
                }

                int a;

                {
                        mixin b!a;
                        mixin b!a;
                }
        }
}

fails with dmd v2.078.1 and error

test.d(11): Error: mixin b!a b isn't a template

However, code:


import std.stdio;

void main() { }

class c {
        this() {
                enum string b(alias d)() {
                        return `writeln("a");`;
                }

                int a;

                //{
                        mixin b!a;
                        mixin b!a;
                //}
        }
}

compiles successfully
Comment 1 Nick Treleaven 2022-05-30 13:55:17 UTC
Is a function allowed to return an `enum string`? Shouldn't you use one of these:

string b(alias d)() {
    return `writeln("a");`;
}

enum string b(alias d) = `writeln("a");`;

I think this should be marked `accepts-invalid`.
Comment 2 Nick Treleaven 2022-05-30 13:58:22 UTC
Also you should use a string mixin, `mixin(b!a);` - not a template mixin.
Comment 3 Nick Treleaven 2022-06-02 15:25:54 UTC
I think mixing in an eponymous template should be an error as it is confusing. Reduced:

void main() {
    template b(alias d) {
        enum b = ``;
    }

    int a;

    {
        pragma(msg, is(typeof(b) == string)); // false
        mixin b!a;
        pragma(msg, is(typeof(b) == string)); // true
        mixin b!a; // error
    }
}

As before, if the {} scope block braces are removed, there's no error.
Comment 4 dlangBugzillaToGithub 2024-12-13 18:56:49 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19382

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB