Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mixin ... isn't a template error when used in new scope #19382

Open
dlangBugzillaToGithub opened this issue Feb 6, 2018 · 3 comments
Open

mixin ... isn't a template error when used in new scope #19382

dlangBugzillaToGithub opened this issue Feb 6, 2018 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

tetyys reported this on 2018-02-06T22:30:31Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18386

CC List

Description

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
@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2022-05-30T13:55:17Z

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`.

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2022-05-30T13:58:22Z

Also you should use a string mixin, `mixin(b!a);` - not a template mixin.

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2022-06-02T15:25:54Z

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant