parent
f41edef4c6
commit
fc7237be7b
|
@ -2131,7 +2131,7 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
|||
}
|
||||
if node.expr_type == table.string_type {
|
||||
cast_to_type_sym := c.table.get_type_symbol(node.typ)
|
||||
if cast_to_type_sym.kind != .alias {
|
||||
if cast_to_type_sym.kind !in [.alias, .sum_type] {
|
||||
mut error_msg := 'cannot cast a string'
|
||||
if node.expr is ast.StringLiteral {
|
||||
str_lit := node.expr as ast.StringLiteral
|
||||
|
|
|
@ -1,10 +1,3 @@
|
|||
vlib/v/checker/tests/match_expr_else.v:4:10: error: cannot cast a string
|
||||
2 |
|
||||
3 | fn main() {
|
||||
4 | x := AA('test')
|
||||
| ~~~~~~
|
||||
5 | _ = match x {
|
||||
6 | int {
|
||||
vlib/v/checker/tests/match_expr_else.v:5:6: error: match must be exhaustive (add match branches for: `f64` or `else {}` at the end)
|
||||
3 | fn main() {
|
||||
4 | x := AA('test')
|
||||
|
|
|
@ -128,3 +128,17 @@ fn test_nested_sumtype() {
|
|||
assert false
|
||||
}
|
||||
}
|
||||
|
||||
type Abc = int | string
|
||||
|
||||
fn test_string_cast_to_sumtype() {
|
||||
a := Abc('test')
|
||||
match a {
|
||||
string {
|
||||
assert true
|
||||
}
|
||||
int {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue