Skip to content

Commit c69f1ee

Browse files
committed
Add regression test for private cross-module constructor (#7152)
1 parent e751322 commit c69f1ee

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//TEST_IGNORE_FILE:
2+
3+
module "private-init-cross-module-helper";
4+
5+
public struct B
6+
{
7+
// A single-parameter constructor with default (internal) visibility. This
8+
// matches the reproducer in issue #7152: calling it across a module
9+
// boundary used to crash the compiler; it must now produce an
10+
// accessibility diagnostic instead.
11+
__init(float b) {}
12+
}
13+
14+
public struct C
15+
{
16+
// The same shape with an *explicit* `private` modifier, to also cover the
17+
// explicit-visibility resolution path.
18+
private __init(float b) {}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Regression test for issue #7152: calling an inaccessible 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+
// `B` uses the implicit (internal) default visibility — matching the issue's
6+
// reproducer — and `C` uses an explicit `private` modifier, so both
7+
// visibility-resolution paths are covered.
8+
9+
//DIAGNOSTIC_TEST:SIMPLE(diag=CHECK):-target spirv
10+
11+
import "private-init-cross-module-helper";
12+
13+
[shader("vertex")]
14+
float4 foo() : SV_Position
15+
{
16+
B bar = B(0.0);
17+
//CHECK: ^ declaration not accessible
18+
//CHECK: ^ 'B.init' is not accessible from the current context.
19+
//CHECK: ^ type mismatch in expression
20+
//CHECK: ^ expected an expression of type 'B', got 'float'
21+
22+
C baz = C(0.0);
23+
//CHECK: ^ declaration not accessible
24+
//CHECK: ^ 'C.init' is not accessible from the current context.
25+
//CHECK: ^ type mismatch in expression
26+
//CHECK: ^ expected an expression of type 'C', got 'float'
27+
return float4(1, 1, 1, 1);
28+
}

0 commit comments

Comments
 (0)