Skip to content

Commit

Permalink
Adding separate construct delegation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
venkataram-nv committed Aug 24, 2024
1 parent 49d8e2b commit 25db183
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
46 changes: 46 additions & 0 deletions tests/diagnostics/uninitialized-fields-delegated.slang
Original file line number Diff line number Diff line change
@@ -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
41 changes: 0 additions & 41 deletions tests/diagnostics/uninitialized-fields.slang
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 25db183

Please sign in to comment.