summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-lookup.cpp18
-rw-r--r--tests/bugs/ptr-extension-this-type.slang28
2 files changed, 45 insertions, 1 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index 604cee2b7..a9b472776 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -959,7 +959,23 @@ static void _lookUpInScopes(
}
}
- _lookUpMembersInType(astBuilder, name, type, request, result, breadcrumbPtr);
+ // When looking up in an extension declaration, we should not automatically
+ // dereference pointer types, as the 'This' type should refer to the
+ // extension target type itself, not the pointed-to type.
+ LookupRequest modifiedRequest = request;
+ if (aggTypeDeclBaseRef.as<ExtensionDecl>())
+ {
+ modifiedRequest.options = (LookupOptions)((uint32_t)modifiedRequest.options |
+ (uint32_t)LookupOptions::NoDeref);
+ }
+
+ _lookUpMembersInType(
+ astBuilder,
+ name,
+ type,
+ modifiedRequest,
+ result,
+ breadcrumbPtr);
}
else
{
diff --git a/tests/bugs/ptr-extension-this-type.slang b/tests/bugs/ptr-extension-this-type.slang
new file mode 100644
index 000000000..627db5302
--- /dev/null
+++ b/tests/bugs/ptr-extension-this-type.slang
@@ -0,0 +1,28 @@
+//TEST:INTERPRET(filecheck=CHECK):
+
+// Test for issue #7656: Compiler segfault with Ptr<T> extension referring to This
+// This test ensures that the compiler doesn't segfault when 'This' is used in Ptr<T> extensions
+
+public interface IThing
+{
+ int f(This other);
+}
+
+public extension Ptr<int>: IThing
+{
+ public int f(This other)
+ {
+ // Test that 'This' refers to Ptr<int>, not the pointed-to type int
+ return sizeof(This) - sizeof(Ptr<int>) + 1;
+ }
+}
+
+void main()
+{
+ Ptr<int> p;
+ Ptr<int> other;
+ int result = p.f(other);
+
+ // CHECK: 1
+ printf("%d\n", result);
+} \ No newline at end of file