www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21585] New: add __traits(totype, string) to convert mangled


          Issue ID: 21585
           Summary: add __traits(totype, string) to convert mangled type
                    string to an existing type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

Add totype as a __trait:

__trait ( totype, AssignExpression )

AssignExpression is evaluated at compile time, and the result must be
a string. The string must be a sequence of characters representing the
mangling of an existing type. The __trait then represents that type.

For example:

pragma(msg, 1.mangleof); // prints `i`
__traits(totype, "i") x;         // declares `x` as having type `int`
__traits(totype, "Pi") p;        // declares `p` as having type `int*`
__traits(totype, 3) y;           // error: `3` is not a string
__traits(totype, "#Hello") z;    // error: `#Hello` is not a recognized
mangling of a type

Earlier work: https://github.com/dlang/dmd/pull/11797

Jan 26 2021