diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2025-06-08 12:54:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-08 19:54:52 +0000 |
| commit | bfac247ff2489a1f7fb9766674a6ed25a48a493b (patch) | |
| tree | fd11188b120d079962c32d3707d418295ce43225 /tests/language-feature/interface-as-rhs-error.slang | |
| parent | 10a3b87db80ae87d6d01ef2af562a732055da1c2 (diff) | |
Fix interface types as RHS of is/as operators (#7234)
Added error checking to reject interface types as the right-hand side
of is and as operators. Enhanced semantic analysis with new diagnostic
30301 and comprehensive test coverage.
Diffstat (limited to 'tests/language-feature/interface-as-rhs-error.slang')
| -rw-r--r-- | tests/language-feature/interface-as-rhs-error.slang | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/language-feature/interface-as-rhs-error.slang b/tests/language-feature/interface-as-rhs-error.slang new file mode 100644 index 000000000..9ad71afde --- /dev/null +++ b/tests/language-feature/interface-as-rhs-error.slang @@ -0,0 +1,73 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +interface IMyInterface +{ + int getValue(); +} + +struct ConcreteImpl : IMyInterface +{ + int getValue() { return 42; } +} + +struct AnotherType +{ + float value; +} + +// No error messages should show for concrete types above +//CHECK-NOT:: error + +// These should produce errors - interface types as RHS +bool testIsOperatorWithInterface<T>() +{ + //CHECK: ([[# @LINE+1]]): error 30301: 'is' and 'as' operators do not support interface types as the right-hand side + return (T is IMyInterface); +} + +void testAsOperatorWithInterface<T>(T value) +{ + //CHECK: ([[# @LINE+1]]): error 30301: 'is' and 'as' operators do not support interface types as the right-hand side + let result = value as IMyInterface; +} + +// No error messages should show for concrete types below +//CHECK-NOT:: error + +// These should work - concrete types as RHS +bool testIsOperatorWithConcreteType<T>() +{ + return (T is ConcreteImpl); // Should compile without error +} + +void testAsOperatorWithConcreteType<T>(T value) +{ + // Test as operator with concrete types - should compile without error + let result = value as ConcreteImpl; +} + +void main() +{ + ConcreteImpl impl; + AnotherType other; + + // Test error cases - these should produce the errors checked above + bool result1 = testIsOperatorWithInterface<ConcreteImpl>(); + testAsOperatorWithInterface<ConcreteImpl>(impl); + + // Test success cases - these should compile without errors + // If ANY of these had errors, compilation would fail + bool result2 = testIsOperatorWithConcreteType<ConcreteImpl>(); + testAsOperatorWithConcreteType<ConcreteImpl>(impl); + + // Additional concrete type tests + bool isTest1 = (impl is ConcreteImpl); + bool isTest2 = (other is AnotherType); + bool isTest3 = (ConcreteImpl is ConcreteImpl); + bool isTest4 = (AnotherType is ConcreteImpl); + + // Test as operator directly + let asTest1 = impl as AnotherType; + let asTest2 = other as ConcreteImpl; + let asTest3 = impl as ConcreteImpl; +} |
