www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17432] New: [DIP1000] scope delegates change type, but not


          Issue ID: 17432
           Summary: [DIP1000] scope delegates change type, but not
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

Consider this code:

module test;
int opApply(scope int delegate() dg) { return dg(); }

// stripped down version of std.traits.Parameters
template Parameters(alias func)
    static if (is(typeof(func) P == function))
        alias Parameters = P;
        static assert(0, "unsupported");

alias op = Parameters!(opApply)[0];
enum typeString = op.stringof;
mixin(typeString ~ " dg;");
alias ty = typeof(dg);

pragma(msg, op.stringof ~ " -> " ~ op.mangleof);
pragma(msg, ty.stringof ~ " -> " ~ ty.mangleof);


Compiling with "dmd -c test.d" prints:
int delegate() -> DFZi
int delegate() -> DFZi

When compiled with "dmd -c -dip1000 test.d", dmd prints:
int delegate() scope -> DFZi
int delegate() scope -> DFNlZi

The type of the scope delegate parameter is modified adding "scope" as a
function attribute, but this is not reflected in the mangling. When reusing its
type elsewhere, the mangling is different.

This is currently blocking https://github.com/dlang/dmd/pull/5855 as it has to
redo the mangling of the delegate whenever it happens to be part of another

May 25