diff options
| author | Yong He <yonghe@outlook.com> | 2025-07-11 15:24:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-11 22:24:41 +0000 |
| commit | 243f522a9087a807d2dadbb3ef201694b6897bf7 (patch) | |
| tree | a5d032f73f59bab3a022c7cc870d3400811b74d5 /source | |
| parent | 39f3c6c7701ed9d7edd5bfd8ee0adf99d2d658e0 (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 'source')
| -rw-r--r-- | source/slang/slang-lookup.cpp | 18 |
1 files changed, 17 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 { |
