Skip to content

Commit 0fe9a69

Browse files
committed
test: add struct/pointer/func interpolation fail tests (#1499)
1 parent 5ee97e4 commit 0fe9a69

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Integration tests compile and run `.ez` programs end-to-end through the full com
5656
- `integration-tests/pass/stdlib/` — 29 stdlib module tests
5757
- `integration-tests/pass/warnings/` — 22 warning detection tests
5858
- `integration-tests/pass/multi-file/` — 31 multi-file import tests (basic, alias, structs, enums, constants, private visibility, transitive, circular, collision, nested, struct functions, imported struct with enum field)
59-
- `integration-tests/fail/errors/`495 error detection tests
59+
- `integration-tests/fail/errors/`498 error detection tests
6060
- `integration-tests/fail/multi-file/` — 20 multi-file error detection tests (collision, private access, type mismatch, undefined module, cross-file error attribution)
6161

6262
**Running:**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Error Test: E3041 - func-typed variable in string interpolation
3+
*
4+
* Regression for #1499: "${f}" where f is a func-typed variable
5+
* holding a function reference used to leak to clang. Typechecker
6+
* now rejects with a hint to call the function or format its result.
7+
* func resolves as TK_UNKNOWN with name "func", so the check keys
8+
* off the name rather than the kind.
9+
*/
10+
11+
do add(a int, b int) -> int {
12+
return a + b
13+
}
14+
15+
do main() {
16+
mut f func = ()add
17+
println("fn: ${f}")
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Error Test: E3041 - pointer value in string interpolation
3+
*
4+
* Regression for #1499: "${ptr}" where ptr is ^T used to leak to
5+
* clang the same way as structs did. Typechecker now rejects with
6+
* a hint to dereference with ^ or format the pointee.
7+
*/
8+
9+
do main() {
10+
mut v int = 42
11+
mut p ^int = addr(v)
12+
println("ptr: ${p}")
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Error Test: E3041 - struct value in string interpolation
3+
*
4+
* Regression for #1499 (bug I reported this session). "${p}" where
5+
* p is a struct used to fall through codegen's default %lld + (long
6+
* long) cast and produce a raw clang diagnostic. Typechecker now
7+
* rejects at the interpolation site with a hint pointing at
8+
* per-field formatting.
9+
*/
10+
11+
const Point struct {
12+
x int
13+
y int
14+
}
15+
16+
do main() {
17+
mut p Point = Point{x: 3, y: 4}
18+
println("point: ${p}")
19+
}

0 commit comments

Comments
 (0)