From d48f050cb0209a4ba9819a094ffd1e7a7c2524ee Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Wed, 25 Jun 2025 12:01:54 -0500 Subject: Fix ambiguous reference for 'extern' and 'export' (#7515) Close #7509. When there are both `export` and `extern` decls in lookup result, we should remove all `extern` decls. --- source/slang/slang-check-overload.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source') diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 8d76d2554..7a89f2e23 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1328,6 +1328,20 @@ int SemanticsVisitor::CompareLookupResultItems( bool rightIsExtension = false; bool leftIsFreeFormExtension = false; bool rightIsFreeFormExtension = false; + bool leftIsExtern = left.declRef.getDecl()->hasModifier(); + bool rigthIsExtern = right.declRef.getDecl()->hasModifier(); + + // If both left and right are extern, then they are equal. + // If only one of them is extern, then the other one is preferred. + // If neither is extern, then we continue with the rest of the checks. + if (leftIsExtern) + { + return (rigthIsExtern ? 0 : 1); + } + if (rigthIsExtern) + { + return (leftIsExtern ? -1 : 0); + } // Prefer declarations that are not in free-form generic extensions, i.e. // `extension T { /* declaration here should have lower precedence. */ } -- cgit v1.2.3