[Issue 24416] New: Add traits for the result of IFTI

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 27 15:32:10 UTC 2024


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

          Issue ID: 24416
           Summary: Add traits for the result of IFTI
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at gmail.com

If I have a function `foo` which has multiple template overloads, which might
be alised, whatever. And I call it using `foo(1, "hi", x, SomeEnum.y)`, the
compiler can figure out what I meant using IFTI, and call the right symbol.

But to *identify* that symbol is nearly impossible. It's not just
`foo!(typeof(1), typeof("hi"), typeof(x), typeof(SomeEnum.y))` because
templates allow all kinds of pattern matching and default values. In order to
inspect the parameter types, you need to first *instantiate* the template,
which is impossible. IFTI does this because it has insider knowledge!

I propose adding a mechanism to search for an overload using an expression.

__traits(getOverload, expression)

Where expression is an expression that is a function call (this is a
requirement), which would provide the exact symbol for overload that would be
called if the expression was executed.

So for example:

```d
void foo(size_t x = size_t.max, T)(T val) if(is(T == int)) {}
void foo(T)(T val) if(is(T == string)) {}

static assert(__traits(isSame(__traits(getOverload, foo(1)), foo!(size_t.max,
int)));
static assert(__traits(isSame(__traits(getOverload, foo("hi")), foo!string));
```

--


More information about the Digitalmars-d-bugs mailing list