diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-09-18 16:49:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-18 14:49:00 -0700 |
| commit | 3240799c00488858afc7eeac9d1dc479609a1040 (patch) | |
| tree | fb9b390a45eec1d27a717d0f1735dbff4059ac9b /tests/diagnostics | |
| parent | 2d83875f4b376f047c4541a6f6c13d36e5aa228b (diff) | |
Lower the priority of looking up the rank of scope (#5065)
* Lower the priority of looking up the rank of scope
In the previous change of #5060, we propose a way to resolve
the ambiguous call when considering the scope of a function.
But this rule should be considered as a low priority than "specialized
candidate", aka. we should consider more "specialized candiate" first.
* Count distance between reference site to declaration site
Compare the candidate by calculating distance
from reference site to declaration site via nearest common prefix
in the scope tree.
This will involve finding the common parent node of two child nodes
and how sum the distance from the common parent to the two child nodes.
* Change the priority higher than 'getOverloadRank'
* Don't evaluate the scope rank algorithm on generic
If the candidate is generic function, the function parameters
won't be checked before 'CompareOverloadCandidates', so it will
results in that the candidates this function could be invalid.
We should not evaluate the distance algorithm in this case, instead
we will evaluate later when the candidate is in flavor of Func or Expr
since then all the type checks for the function will be done.
Diffstat (limited to 'tests/diagnostics')
| -rw-r--r-- | tests/diagnostics/overload-ambiguous.slang | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/diagnostics/overload-ambiguous.slang b/tests/diagnostics/overload-ambiguous.slang new file mode 100644 index 000000000..0c8f7bd21 --- /dev/null +++ b/tests/diagnostics/overload-ambiguous.slang @@ -0,0 +1,45 @@ +// https://github.com/shader-slang/slang/issues/4476 + +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): +RWStructuredBuffer<uint> outputBuffer; + +namespace A1 +{ + uint func() + { + return 1u; + } + + namespace A2 + { + uint func() + { + return 2u; + } + } +} +namespace B1 +{ + uint func() + { + return 4u; + } +} + +[numthreads(1, 1, 1)] +[shader("compute")] +void computeMain(uint3 threadID: SV_DispatchThreadID) +{ + using namespace A1; + using namespace A1::A2; + using namespace B1; + using namespace C1; + + // Only A1::func() and B1::func() will cause ambiguity because the distance from + // the reference site to those two functions declaration are the same. + outputBuffer[0] = func(); + // CHECK-NOT: {{.*}}A2::func() -> uint + // CHECK: ambiguous call to 'func' with arguments of type () + // CHECK: candidate: func B1::func() -> uint + // CHECK: candidate: func A1::func() -> uint +} |
