summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-11 15:24:41 -0700
committerGitHub <noreply@github.com>2025-07-11 22:24:41 +0000
commit243f522a9087a807d2dadbb3ef201694b6897bf7 (patch)
treea5d032f73f59bab3a022c7cc870d3400811b74d5 /tests
parent39f3c6c7701ed9d7edd5bfd8ee0adf99d2d658e0 (diff)
Fix segfault with Ptr<T> extension using 'This' type reference (#7719)
* Fix segfault with Ptr<T> extension using 'This' type reference Set LookupOptions::NoDeref when looking up target type members within extension declarations to prevent automatic pointer dereferencing that was causing breadcrumb handling issues and segfaults. Fixes #7656 Co-authored-by: Yong He <csyonghe@users.noreply.github.com> * Enhance test for ptr-extension-this-type to verify correctness with interpreter - Changed function to return sizeof(This) - sizeof(Ptr<int>) + 1 - Modified test to use interpreter with filecheck to verify result equals 1 - Added main() function that calls the extension method and prints result - Verifies that 'This' correctly refers to Ptr<int> in extension context Co-authored-by: Yong He <csyonghe@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Yong He <csyonghe@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/ptr-extension-this-type.slang28
1 files changed, 28 insertions, 0 deletions
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