File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -3318,8 +3318,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
3318
3318
}
3319
3319
}
3320
3320
}
3321
- if mut node.expr is ast.StringLiteral {
3322
- c.add_error_detail ('use ${c.table.type_to_str(node.typ)} .from_string(\' ${node.expr.val} \' ) instead' )
3321
+ if node.expr_type == ast.string_type_idx {
3322
+ c.add_error_detail ('use ${c.table.type_to_str(node.typ)} .from_string(${node.expr} ) instead' )
3323
3323
c.error ('cannot cast `string` to `enum`' , node.pos)
3324
3324
}
3325
3325
}
Original file line number Diff line number Diff line change @@ -3,5 +3,13 @@ vlib/v/checker/tests/string_to_enum_cast_err.vv:8:7: error: cannot cast `string`
3
3
7 | fn main() {
4
4
8 | _ := Test('one')
5
5
| ~~~~~~~~~~~
6
- 9 | }
6
+ 9 |
7
+ 10 | my_str := 'one'
7
8
Details: use main.Test.from_string('one') instead
9
+ vlib/v/checker/tests/string_to_enum_cast_err.vv:11:7: error: cannot cast `string` to `enum`
10
+ 9 |
11
+ 10 | my_str := 'one'
12
+ 11 | _ := Test(my_str)
13
+ | ~~~~~~~~~~~~
14
+ 12 | }
15
+ Details: use main.Test.from_string(my_str) instead
Original file line number Diff line number Diff line change @@ -6,4 +6,7 @@ enum Test {
6
6
7
7
fn main() {
8
8
_ := Test('one')
9
+
10
+ my_str := 'one'
11
+ _ := Test(my_str)
9
12
}
You can’t perform that action at this time.
0 commit comments