From ea15647ba6bccb5ac48de5f4b80b8c2769d69b8f Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 7 Apr 2023 10:12:00 -0700 Subject: Diagnose on attempt to specialize with interface type. (#2780) * Diagnose on attempt to specialize with interface type. Fixes ##1445. * Enable fixed test. * Fix test. * Fix. --------- Co-authored-by: Yong He --- .../diagnostics/generic-type-inference-fail.slang | 81 ++++++++++++++++++++++ .../generic-type-inference-fail.slang.expected | 9 +++ 2 files changed, 90 insertions(+) create mode 100644 tests/diagnostics/generic-type-inference-fail.slang create mode 100644 tests/diagnostics/generic-type-inference-fail.slang.expected (limited to 'tests/diagnostics') diff --git a/tests/diagnostics/generic-type-inference-fail.slang b/tests/diagnostics/generic-type-inference-fail.slang new file mode 100644 index 000000000..803c7584c --- /dev/null +++ b/tests/diagnostics/generic-type-inference-fail.slang @@ -0,0 +1,81 @@ +//DIAGNOSTIC_TEST:SIMPLE: + +interface IAssoc +{ + int Compute(); +} + +interface IInterface +{ + associatedtype TAssoc : IAssoc; + + [mutating] + void SetVal(int inVal); + + TAssoc GetAssoc(); +}; + +T.TAssoc CreateT_Assoc_Inner(int inVal) +{ + T obj; + obj.SetVal(inVal); + return obj.GetAssoc(); +} + +T.TAssoc CreateT_Assoc(int inVal) +{ + return CreateT_Assoc_Inner(inVal); +} + +T CreateT(int inVal) +{ + T obj; + obj.SetVal(inVal); + return obj; +} + +struct Impl : IInterface +{ + struct TAssoc : IAssoc + { + int base; + int Compute() + { + return base; + } + }; + + TAssoc assoc; + [mutating] + void SetVal(int inVal) + { + assoc.base = inVal; + } + + TAssoc GetAssoc() + { + return assoc; + } +}; + +int test() +{ + var obj = CreateT(2); + var obj2 = CreateT_Assoc(1); + + var obj3 = CreateT_Assoc_Inner(1); // ERROR. + + return obj.GetAssoc().Compute() + obj2.Compute() + obj3.Compute(); +} + + +//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer : register(u0); + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int outVal = test(); + outputBuffer[tid] = outVal; +} \ No newline at end of file diff --git a/tests/diagnostics/generic-type-inference-fail.slang.expected b/tests/diagnostics/generic-type-inference-fail.slang.expected new file mode 100644 index 000000000..3f9753d68 --- /dev/null +++ b/tests/diagnostics/generic-type-inference-fail.slang.expected @@ -0,0 +1,9 @@ +result code = -1 +standard error = { +tests/diagnostics/generic-type-inference-fail.slang(66): error 39999: could not specialize generic for arguments of type (int) + var obj3 = CreateT_Assoc_Inner(1); // ERROR. + ^ +tests/diagnostics/generic-type-inference-fail.slang(18): note 39999: see declaration of func CreateT_Assoc_Inner(int) -> T.TAssoc +} +standard output = { +} -- cgit v1.2.3