Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix missing check for invalid argument for builtin #23515

Merged
merged 5 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion vlib/v/checker/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
mut ftyp := c.expr(mut expr)
ftyp = c.type_resolver.get_type_or_default(expr, c.check_expr_option_or_result_call(expr,
ftyp))
if ftyp == ast.void_type {
if ftyp == ast.void_type || ftyp == 0 {
c.error('expression does not return a value', expr.pos())
} else if ftyp == ast.char_type && ftyp.nr_muls() == 0 {
c.error('expression returning type `char` cannot be used in string interpolation directly, print its address or cast it to an integer instead',
expr.pos())
}
if ftyp == 0 {
return ast.void_type
}
c.markused_string_inter_lit(mut node, ftyp)
c.fail_if_unreadable(expr, ftyp, 'interpolation object')
node.expr_types << ftyp
Expand Down
49 changes: 49 additions & 0 deletions vlib/v/checker/tests/invalid_generic_field_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
vlib/v/checker/tests/invalid_generic_field_err.vv:4:15: error: type `User` has no field named `typo`
2 |
3 | fn (u &User) debug_1() {
4 | println('${u.typo}')
| ~~~~
5 | }
6 |
vlib/v/checker/tests/invalid_generic_field_err.vv:4:15: error: expression does not return a value
2 |
3 | fn (u &User) debug_1() {
4 | println('${u.typo}')
| ~~~~
5 | }
6 |
vlib/v/checker/tests/invalid_generic_field_err.vv:8:9: error: `User` has no property `typo`
6 |
7 | fn debug_2[T](t T) {
8 | _ := t.typo
| ~~~~
9 | }
10 |
vlib/v/checker/tests/invalid_generic_field_err.vv:8:4: error: assignment mismatch: 1 variable 0 values
6 |
7 | fn debug_2[T](t T) {
8 | _ := t.typo
| ~~
9 | }
10 |
vlib/v/checker/tests/invalid_generic_field_err.vv:12:15: error: `User` has no property `typo`
10 |
11 | fn debug_3[T](t T) {
12 | println('${t.typo}')
| ~~~~
13 | }
14 |
vlib/v/checker/tests/invalid_generic_field_err.vv:12:15: error: expression does not return a value
10 |
11 | fn debug_3[T](t T) {
12 | println('${t.typo}')
| ~~~~
13 | }
14 |
vlib/v/checker/tests/invalid_generic_field_err.vv:12:2: error: `println` can not print void expressions
10 |
11 | fn debug_3[T](t T) {
12 | println('${t.typo}')
| ~~~~~~~~~~~~~~~~~~~~
13 | }
14 |
20 changes: 20 additions & 0 deletions vlib/v/checker/tests/invalid_generic_field_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct User {}

fn (u &User) debug_1() {
println('${u.typo}')
}

fn debug_2[T](t T) {
_ := t.typo
}

fn debug_3[T](t T) {
println('${t.typo}')
}

fn main() {
u := &User{}
u.debug_1()
debug_2(u)
debug_3(u)
}
Loading