[Issue 13850] mixin template accepts delegates as function parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 30 06:33:38 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=13850

Max Samukha <maxsamukha at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WORKSFORME                  |---

--- Comment #5 from Max Samukha <maxsamukha at gmail.com> ---
(In reply to Salih Dincer from comment #4)

> You are right, because there is alias!

I am not sure what you mean exactly, but functions passed by alias are
correctly rejected if they are used in a wrong context. Consider:

mixin template Template(void function() func1, alias func2) {
    static void foo() {
        func1(); // UB
        // func2(); // This fails to compile
    }
};

class SomeClass {

    int x;
    mixin Template!(&func23);

    void func23() {
        x = 1;
    }
}

void main() {
    SomeClass a = new SomeClass;
    a.foo();
    assert(a.x == 1); // Fails
}

I am reopening this. Local function types have been an embarrassment for
decades and should be fixed.

--


More information about the Digitalmars-d-bugs mailing list