mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
029d583bb2
commit
758f84fa86
@ -401,7 +401,7 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, str_fn_
|
||||
mut clean_sum_type_v_type_name := ''
|
||||
if info.is_anon {
|
||||
variant_names := info.variants.map(util.strip_main_name(g.table.sym(it).name))
|
||||
clean_sum_type_v_type_name = '(${variant_names.join(' | ')})'
|
||||
clean_sum_type_v_type_name = '${variant_names.join('|')}'
|
||||
} else {
|
||||
clean_sum_type_v_type_name = styp.replace('__', '.')
|
||||
if styp.ends_with('*') {
|
||||
|
@ -2493,6 +2493,24 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
||||
typ: typ
|
||||
pos: type_pos
|
||||
}
|
||||
} else if !known_var && language == .v && (p.table.known_type(p.tok.lit) || lit0_is_capital)
|
||||
&& p.peek_tok.kind == .pipe {
|
||||
start_pos := p.tok.pos()
|
||||
mut to_typ := p.parse_type()
|
||||
p.check(.lpar)
|
||||
expr := p.expr(0)
|
||||
end_pos := p.tok.pos()
|
||||
p.check(.rpar)
|
||||
node = ast.CastExpr{
|
||||
typ: to_typ
|
||||
typname: p.table.sym(to_typ).name
|
||||
expr: expr
|
||||
arg: ast.empty_expr()
|
||||
has_arg: false
|
||||
pos: start_pos.extend(end_pos)
|
||||
}
|
||||
p.expr_mod = ''
|
||||
return node
|
||||
}
|
||||
|
||||
ident := p.parse_ident(language)
|
||||
|
7
vlib/v/tests/cast_to_anon_sumtype_test.v
Normal file
7
vlib/v/tests/cast_to_anon_sumtype_test.v
Normal file
@ -0,0 +1,7 @@
|
||||
module main
|
||||
|
||||
fn test_cast_to_anon_sumtype() {
|
||||
x := string|none(none)
|
||||
println(x)
|
||||
assert '$x' == 'string|none(none)'
|
||||
}
|
Loading…
Reference in New Issue
Block a user