yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Julius IkkalaMinimal optional constraints (#7422)7349dc5cf

master
2.0 KiB73 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target spirv
2
3interface IMyInterface
4{
5    int getValue();
6}
7
8struct ConcreteImpl : IMyInterface
9{
10    int getValue() { return 42; }
11}
12
13struct AnotherType
14{
15    float value;
16}
17
18// No error messages should show for concrete types above
19//CHECK-NOT:: error
20
21// These should produce errors - interface types as RHS
22bool testIsOperatorWithInterface<T>()
23{
24    //CHECK: ([[# @LINE+1]]): error 30301: cannot use 'is' operator with an interface type as the right-hand side
25    return (T is IMyInterface);
26}
27
28void testAsOperatorWithInterface<T>(T value)
29{
30    //CHECK: ([[# @LINE+1]]): error 30302: cannot use 'as' operator with an interface type as the right-hand side
31    let result = value as IMyInterface;
32}
33
34// No error messages should show for concrete types below
35//CHECK-NOT:: error
36
37// These should work - concrete types as RHS
38bool testIsOperatorWithConcreteType<T>()
39{
40    return (T is ConcreteImpl); // Should compile without error
41}
42
43void testAsOperatorWithConcreteType<T>(T value)
44{
45    // Test as operator with concrete types - should compile without error
46    let result = value as ConcreteImpl;
47}
48
49void main()
50{
51    ConcreteImpl impl;
52    AnotherType other;
53
54    // Test error cases - these should produce the errors checked above
55    bool result1 = testIsOperatorWithInterface<ConcreteImpl>();
56    testAsOperatorWithInterface<ConcreteImpl>(impl);
57
58    // Test success cases - these should compile without errors
59    // If ANY of these had errors, compilation would fail
60    bool result2 = testIsOperatorWithConcreteType<ConcreteImpl>();
61    testAsOperatorWithConcreteType<ConcreteImpl>(impl);
62
63    // Additional concrete type tests
64    bool isTest1 = (impl is ConcreteImpl);
65    bool isTest2 = (other is AnotherType);
66    bool isTest3 = (ConcreteImpl is ConcreteImpl);
67    bool isTest4 = (AnotherType is ConcreteImpl);
68
69    // Test as operator directly
70    let asTest1 = impl as AnotherType;
71    let asTest2 = other as ConcreteImpl;
72    let asTest3 = impl as ConcreteImpl;
73}