mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
This commit is contained in:
parent
b51dfcfe7d
commit
cf0100f140
@ -47,12 +47,15 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
|
|||||||
mut ftyp := c.expr(mut expr)
|
mut ftyp := c.expr(mut expr)
|
||||||
ftyp = c.type_resolver.get_type_or_default(expr, c.check_expr_option_or_result_call(expr,
|
ftyp = c.type_resolver.get_type_or_default(expr, c.check_expr_option_or_result_call(expr,
|
||||||
ftyp))
|
ftyp))
|
||||||
if ftyp == ast.void_type {
|
if ftyp == ast.void_type || ftyp == 0 {
|
||||||
c.error('expression does not return a value', expr.pos())
|
c.error('expression does not return a value', expr.pos())
|
||||||
} else if ftyp == ast.char_type && ftyp.nr_muls() == 0 {
|
} 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',
|
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())
|
expr.pos())
|
||||||
}
|
}
|
||||||
|
if ftyp == 0 {
|
||||||
|
return ast.void_type
|
||||||
|
}
|
||||||
c.markused_string_inter_lit(mut node, ftyp)
|
c.markused_string_inter_lit(mut node, ftyp)
|
||||||
c.fail_if_unreadable(expr, ftyp, 'interpolation object')
|
c.fail_if_unreadable(expr, ftyp, 'interpolation object')
|
||||||
node.expr_types << ftyp
|
node.expr_types << ftyp
|
||||||
|
49
vlib/v/checker/tests/invalid_generic_field_err.out
Normal file
49
vlib/v/checker/tests/invalid_generic_field_err.out
Normal file
@ -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
vlib/v/checker/tests/invalid_generic_field_err.vv
Normal file
20
vlib/v/checker/tests/invalid_generic_field_err.vv
Normal file
@ -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…
x
Reference in New Issue
Block a user