diff options
| author | Yong He <yonghe@outlook.com> | 2017-12-28 17:38:05 -0500 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2017-12-28 17:39:14 -0500 |
| commit | 9efd9597c50d4dbbf57a9285085aab044ed6c8c0 (patch) | |
| tree | 506ff773e065280b58c8b67f0c6dccbd7a8c9114 | |
| parent | 69242398be1ba76898c0d6541eec3b7ca0ec1ab4 (diff) | |
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.
| -rw-r--r-- | source/slang/syntax.cpp | 2 | ||||
| -rw-r--r-- | tests/compute/assoctype-func-param.slang | 53 | ||||
| -rw-r--r-- | tests/compute/assoctype-func-param.slang.expected.txt | 4 |
3 files changed, 58 insertions, 1 deletions
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index 070362ddf..e67e21883 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -503,7 +503,7 @@ void Type::accept(IValVisitor* visitor, void* extra) if (aggTypeDeclRef.getDecl()->memberDictionary.TryGetValue(assocTypeDecl->getName(), targetType)) { if (auto typeDefDecl = dynamic_cast<TypeDefDecl*>(targetType)) - return typeDefDecl->type.type; + return typeDefDecl->type.type->Substitute(aggTypeDeclRef.substitutions); else return DeclRefType::Create(getSession(), DeclRef<Decl>(targetType, aggTypeDeclRef.substitutions)); } 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<float> outputBuffer; + +interface IBase +{ + associatedtype SubTypeT; + associatedtype RetT; + RetT getVal(SubTypeT t); + SubTypeT setVal(RetT v); +} + +struct SubType<T> +{ + T x; +}; + +struct GenStruct<T> : IBase +{ + typedef T RetT; + typedef SubType<RetT> SubTypeT; + SubTypeT setVal(T val) + { + SubTypeT rs; + rs.x = val; + return rs; + } + T getVal(SubTypeT v) + { + return v.x; + } +}; + +U.RetT test<U:IBase>(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<GenStruct<float> >(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 |
