From 9efd9597c50d4dbbf57a9285085aab044ed6c8c0 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 28 Dec 2017 17:38:05 -0500 Subject: Fix substitution for associatedtype. fixes #341 When a typedef definition is used to satisfy an associated type, we must also substitute the resulting typedef type using parent substitution, in the case that the typedef is a generic application. --- tests/compute/assoctype-func-param.slang | 53 ++++++++++++++++++++++ .../assoctype-func-param.slang.expected.txt | 4 ++ 2 files changed, 57 insertions(+) create mode 100644 tests/compute/assoctype-func-param.slang create mode 100644 tests/compute/assoctype-func-param.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/assoctype-func-param.slang b/tests/compute/assoctype-func-param.slang new file mode 100644 index 000000000..63acfb23a --- /dev/null +++ b/tests/compute/assoctype-func-param.slang @@ -0,0 +1,53 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +// Test type checking of associatedtype and typedef + +RWStructuredBuffer outputBuffer; + +interface IBase +{ + associatedtype SubTypeT; + associatedtype RetT; + RetT getVal(SubTypeT t); + SubTypeT setVal(RetT v); +} + +struct SubType +{ + T x; +}; + +struct GenStruct : IBase +{ + typedef T RetT; + typedef SubType SubTypeT; + SubTypeT setVal(T val) + { + SubTypeT rs; + rs.x = val; + return rs; + } + T getVal(SubTypeT v) + { + return v.x; + } +}; + +U.RetT test(U.RetT val) +{ + U obj; + U.SubTypeT sb = obj.setVal(val); + return obj.getVal(sb); +} + + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + float inVal = float(tid); + /* wrong error message for the following line */ + float outVal = test >(inVal); + outputBuffer[tid] = outVal.x; +} \ No newline at end of file diff --git a/tests/compute/assoctype-func-param.slang.expected.txt b/tests/compute/assoctype-func-param.slang.expected.txt new file mode 100644 index 000000000..98798bd61 --- /dev/null +++ b/tests/compute/assoctype-func-param.slang.expected.txt @@ -0,0 +1,4 @@ +0 +3F800000 +40000000 +40400000 \ No newline at end of file -- cgit v1.2.3