Skip to content

Commit 2fb9d56

Browse files
committed
Add regression test for private cross-module constructor (#7152)
Calling a private single-parameter constructor of a struct defined in a separate module used to segfault. It now reports an accessibility error; add a regression test to lock that in. Fixes #7152.
1 parent a214f7d commit 2fb9d56

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module "private-init-cross-module-helper";
2+
3+
public struct B
4+
{
5+
// A private single-parameter constructor in a separate module. Calling
6+
// this from another module used to crash the compiler (see issue #7152);
7+
// it must now produce an accessibility diagnostic instead.
8+
__init(float b) {}
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for issue #7152: calling a private single-parameter
2+
// constructor of a struct defined in a separate module used to segfault.
3+
// It must now report an accessibility error rather than crash.
4+
5+
//DIAGNOSTIC_TEST:SIMPLE(diag=CHECK):-target spirv
6+
7+
import "private-init-cross-module-helper.slang";
8+
9+
[shader("vertex")]
10+
float4 foo() : SV_Position
11+
{
12+
B bar = B(0.0);
13+
//CHECK: ^ declaration not accessible
14+
//CHECK: ^ 'B.init' is not accessible from the current context.
15+
//CHECK: ^ type mismatch in expression
16+
//CHECK: ^ expected an expression of type 'B', got 'float'
17+
return float4(1, 1, 1, 1);
18+
}

0 commit comments

Comments
 (0)