From 462ea4e66569efa978e4057ea2d041c69d4a729b Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 10 Oct 2025 14:34:56 -0700 Subject: Fix `specializeRTTIObject` to use non-zero RTTI value to work with `Optional`. (#8677) Closes #8673. The issue is that we use the RTTI field of an existential to check if it is null. We have the logic to help the user to fill in a non-zero value for the RTTI field when such an object is filled from the host. However, when there is slang code creating an existential value, we still have old logic in the compiler that just fills in 0 for the RTTI field, causing an `Optional.hasValue` to always return false in such cases. --- tests/language-feature/types/optional-ifoo.slang | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/language-feature/types/optional-ifoo.slang (limited to 'tests/language-feature/types') diff --git a/tests/language-feature/types/optional-ifoo.slang b/tests/language-feature/types/optional-ifoo.slang new file mode 100644 index 000000000..d2c9b6a50 --- /dev/null +++ b/tests/language-feature/types/optional-ifoo.slang @@ -0,0 +1,26 @@ +//TEST:INTERPRET(filecheck=CHECK): + +interface IFoo +{ + int get_result(); +} + +struct FooImpl : IFoo +{ + int get_result() { return data; } + int data; +} + +Optional generate_foo(int i) +{ + FooImpl result = {}; + result.data = i; + return { result }; +} + +void main() +{ + // CHECK: hasValue: 1 + let result_foo = generate_foo(100); + printf("hasValue: %d\n", (int)result_foo.hasValue); +} -- cgit v1.2.3