From 25db1838ff34aa5772b8a5b967d6c3c4e2c13cd0 Mon Sep 17 00:00:00 2001 From: Venkataram Sivaram Date: Fri, 23 Aug 2024 17:35:29 -0700 Subject: [PATCH] Adding separate construct delegation tests --- .../uninitialized-fields-delegated.slang | 46 +++++++++++++++++++ tests/diagnostics/uninitialized-fields.slang | 41 ----------------- 2 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 tests/diagnostics/uninitialized-fields-delegated.slang diff --git a/tests/diagnostics/uninitialized-fields-delegated.slang b/tests/diagnostics/uninitialized-fields-delegated.slang new file mode 100644 index 0000000000..e3777f477f --- /dev/null +++ b/tests/diagnostics/uninitialized-fields-delegated.slang @@ -0,0 +1,46 @@ +//TEST:SIMPLE(filecheck=CHK): -target spirv + +// Delegated constructors +struct Impl +{ + float x; + + __init(float val) + { + x = val; + } + + __init() + { + float val = 2.0; + + // Shouldn't trigger a warning here + return Impl(val); + } +} + +// Calling a method from a constructor to initialize fields +struct HitInfo +{ + float3 barycentrics; + uint primitiveIndex; + + [[mutating]] void init(float2 hitBarycentrics, uint hitPrimitiveIndex) + { + barycentrics = { 1.0 - hitBarycentrics.x - hitBarycentrics.y, hitBarycentrics.x, hitBarycentrics.y }; + primitiveIndex = hitPrimitiveIndex; + } + + __init(float2 hitBarycentrics, uint hitPrimitiveIndex) + { + init(hitBarycentrics, hitPrimitiveIndex); + } + + __init(BuiltInTriangleIntersectionAttributes attr) + { + init(attr.barycentrics, PrimitiveIndex()); + } +} + +//CHK-NOT: warning 41020 +//CHK-NOT: warning 41021 diff --git a/tests/diagnostics/uninitialized-fields.slang b/tests/diagnostics/uninitialized-fields.slang index df2224d5b8..c5fa37aade 100644 --- a/tests/diagnostics/uninitialized-fields.slang +++ b/tests/diagnostics/uninitialized-fields.slang @@ -86,46 +86,5 @@ struct Pass int y = 0; } -struct Impl -{ - float x; - - __init(float val) - { - x = val; - } - - __init() - { - float val = 2.0; - - // Shouldn't trigger a warning here - return Impl(val); - } -} - -// Calling a method from a constructor to initialize fields -struct HitInfo -{ - float3 barycentrics; - uint primitiveIndex; - - [[mutating]] void init(float2 hitBarycentrics, uint hitPrimitiveIndex) - { - barycentrics = { 1.0 - hitBarycentrics.x - hitBarycentrics.y, hitBarycentrics.x, hitBarycentrics.y }; - primitiveIndex = hitPrimitiveIndex; - } - - __init(float2 hitBarycentrics, uint hitPrimitiveIndex) - { - init(hitBarycentrics, hitPrimitiveIndex); - } - - __init(BuiltInTriangleIntersectionAttributes attr) - { - init(attr.barycentrics, PrimitiveIndex()); - } -} - //CHK-NOT: warning 41020 //CHK-NOT: warning 41021