diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2025-05-22 21:29:06 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-22 19:29:06 -0700 |
| commit | 3072cfea95aad2a9ddab0f517c8f18f634442a27 (patch) | |
| tree | 966c019c35604b0f457caec02c9619feddbf2665 /tests/initializer-list/partial-init.slang | |
| parent | 2d34409f2e72673ac9fd766eaeaa75f60882e7ca (diff) | |
Implement default initializer list for C-Style type member (#7079)
* Implement default initializer list for C-Style type member
Close #6189.
Previsouly, for the C-Style member in a struct, if it doesn't have any initialize
expression, when we synthesize the ctor, we will not associate the
default value for the parameter corresponding to that member.
This bring some trouble that existing slang users has to add '= {}' to
every struct fields in order to make all the parameters in the synthesized ctor having
a default value, so people can still use `Struct a = {}` to create a
struct.
To make this use case convenience, we will automatically associated a
'= {}' as the default value for this case.
This PR also add support for empty initializing link-time sized vector/matrix by "= {}".
In addition, this PR also fix a bug in auto diff where we should not report error when proccessing
transpose on an empty struct.
Diffstat (limited to 'tests/initializer-list/partial-init.slang')
| -rw-r--r-- | tests/initializer-list/partial-init.slang | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/initializer-list/partial-init.slang b/tests/initializer-list/partial-init.slang index 55f3816fb..a4739f041 100644 --- a/tests/initializer-list/partial-init.slang +++ b/tests/initializer-list/partial-init.slang @@ -8,15 +8,15 @@ struct PartialInit { int x; int y = 1; // compiler synthesizes: - // __init(int x, int y = 1); + // __init(int x = {}, int y = 1); } struct PartialInit2 { int x = 1; int y; - // __init(int x, int y); + // __init(int x, int y = {}); } -//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0], stride=4):out,name=outputBuffer +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<int> outputBuffer; void test() { @@ -38,6 +38,18 @@ void test() outputBuffer[4] = p3.x; // BUFFER-NEXT: 5 outputBuffer[5] = p3.y; + + PartialInit p4 = {}; // calls `__init`, result is {0, 1} + // BUFFER-NEXT: 0 + outputBuffer[6] = p4.x; + // BUFFER-NEXT: 1 + outputBuffer[7] = p4.y; + + PartialInit2 p5 = {}; // calls `__init`, result is {1, 0} + // BUFFER-NEXT: 1 + outputBuffer[8] = p5.x; + // BUFFER-NEXT: 0 + outputBuffer[9] = p5.y; } [shader("compute")] |
