diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-30 23:38:34 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-30 23:38:34 -0800 |
| commit | 88e221bad60ce20087fe2f8a85d506be36a6e6ca (patch) | |
| tree | 1a3c546d8a242c96dfe0fb0056ac891bd8394942 /tests/language-feature | |
| parent | 89dd2b1278f9e457d9d343742a51de27502ebca1 (diff) | |
Fix requirement candidate lookup to prefer decls in the same paraent as the inheritance decl. (#5965)
Diffstat (limited to 'tests/language-feature')
| -rw-r--r-- | tests/language-feature/interfaces/overloaded-associatedtype.slang | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/language-feature/interfaces/overloaded-associatedtype.slang b/tests/language-feature/interfaces/overloaded-associatedtype.slang new file mode 100644 index 000000000..4630c76a6 --- /dev/null +++ b/tests/language-feature/interfaces/overloaded-associatedtype.slang @@ -0,0 +1,43 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type + +interface IFoo<T> { + associatedtype Output : IBar; + func foo(other: T) -> Output; +} + +interface IBar { int getId(); } + +struct Ant:IBar { int getId() { return 0; } }; +struct Bat:IBar { int getId() { return 1; } }; +struct Cat:IBar { int getId() { return 2; } }; +struct Dog:IBar { int getId() { return 3; } }; +struct Ewe:IBar { int getId() { return 4; } }; +struct Fox:IBar { int getId() { return 5; } }; +struct Gnu:IBar { int getId() { return 6; } }; + +extension Ant: IFoo<Bat> { + typedef Cat Output; + func foo(other: Bat) -> Cat { return Cat(); } +} +extension Ant: IFoo<Dog> { + typedef Ewe Output; + func foo(other: Dog) -> Ewe { return Ewe(); } +} +extension Ant: IFoo<Fox> { + typedef Gnu Output; + func foo(other: Fox) -> Gnu { return Gnu(); } +} + +int test<T:IFoo<Fox>>(T v) { + return v.foo(Fox()).getId(); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=output +RWStructuredBuffer<int> output; + +[numthreads(1,1,1)] +void computeMain() { + Ant a; + // CHECK: 6 + output[0] = test(a); +}
\ No newline at end of file |
