Skip to content

Commit cf0100f

Browse files
authored
checker: fix missing check for invalid argument for builtin (fix #23511) (#23515)
1 parent b51dfcf commit cf0100f

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

vlib/v/checker/str.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
4747
mut ftyp := c.expr(mut expr)
4848
ftyp = c.type_resolver.get_type_or_default(expr, c.check_expr_option_or_result_call(expr,
4949
ftyp))
50-
if ftyp == ast.void_type {
50+
if ftyp == ast.void_type || ftyp == 0 {
5151
c.error('expression does not return a value', expr.pos())
5252
} else if ftyp == ast.char_type && ftyp.nr_muls() == 0 {
5353
c.error('expression returning type `char` cannot be used in string interpolation directly, print its address or cast it to an integer instead',
5454
expr.pos())
5555
}
56+
if ftyp == 0 {
57+
return ast.void_type
58+
}
5659
c.markused_string_inter_lit(mut node, ftyp)
5760
c.fail_if_unreadable(expr, ftyp, 'interpolation object')
5861
node.expr_types << ftyp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
vlib/v/checker/tests/invalid_generic_field_err.vv:4:15: error: type `User` has no field named `typo`
2+
2 |
3+
3 | fn (u &User) debug_1() {
4+
4 | println('${u.typo}')
5+
| ~~~~
6+
5 | }
7+
6 |
8+
vlib/v/checker/tests/invalid_generic_field_err.vv:4:15: error: expression does not return a value
9+
2 |
10+
3 | fn (u &User) debug_1() {
11+
4 | println('${u.typo}')
12+
| ~~~~
13+
5 | }
14+
6 |
15+
vlib/v/checker/tests/invalid_generic_field_err.vv:8:9: error: `User` has no property `typo`
16+
6 |
17+
7 | fn debug_2[T](t T) {
18+
8 | _ := t.typo
19+
| ~~~~
20+
9 | }
21+
10 |
22+
vlib/v/checker/tests/invalid_generic_field_err.vv:8:4: error: assignment mismatch: 1 variable 0 values
23+
6 |
24+
7 | fn debug_2[T](t T) {
25+
8 | _ := t.typo
26+
| ~~
27+
9 | }
28+
10 |
29+
vlib/v/checker/tests/invalid_generic_field_err.vv:12:15: error: `User` has no property `typo`
30+
10 |
31+
11 | fn debug_3[T](t T) {
32+
12 | println('${t.typo}')
33+
| ~~~~
34+
13 | }
35+
14 |
36+
vlib/v/checker/tests/invalid_generic_field_err.vv:12:15: error: expression does not return a value
37+
10 |
38+
11 | fn debug_3[T](t T) {
39+
12 | println('${t.typo}')
40+
| ~~~~
41+
13 | }
42+
14 |
43+
vlib/v/checker/tests/invalid_generic_field_err.vv:12:2: error: `println` can not print void expressions
44+
10 |
45+
11 | fn debug_3[T](t T) {
46+
12 | println('${t.typo}')
47+
| ~~~~~~~~~~~~~~~~~~~~
48+
13 | }
49+
14 |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct User {}
2+
3+
fn (u &User) debug_1() {
4+
println('${u.typo}')
5+
}
6+
7+
fn debug_2[T](t T) {
8+
_ := t.typo
9+
}
10+
11+
fn debug_3[T](t T) {
12+
println('${t.typo}')
13+
}
14+
15+
fn main() {
16+
u := &User{}
17+
u.debug_1()
18+
debug_2(u)
19+
debug_3(u)
20+
}

0 commit comments

Comments
 (0)