shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

Unexpected ambiguous call. #4476

Open tomas-davidovic opened 3 days ago

tomas-davidovic commented 3 days ago

In code like this:

uniform uint gData;

uint getData()
{
    return gData;
}

struct DataObtainer
{
    uint data;
    uint getData()
    {
        return data;
    }

    uint getValue()
    {
        return getData(); /// This is ambiguous call
    }
}

[numthreads(16, 1, 1)]
void testGetData(uint3 threadID: SV_DispatchThreadID)
{
    DataObtainer obtainer;
    output[0] = getData();
    output[1] = obtainer.getData();
    output[2] = obtainer.getValue();
}

The call to getData() inside getValue() is reported as an ambiguous call. This is incosistent with C/C++, where the compiler will automatically prefer the member function getData(), without needing to explicitly specify this.getData() or ::getData().

ArielG-NV commented 3 days ago

I don't know if this is intentional behavior.

As a note for implementation, if this is a bug the solution should be simple. Overload resolution would just need to prefer functions with equal parents (slang-check-overload.cpp).