mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
f922ed0941
commit
0e49ce427e
@ -2306,7 +2306,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
|
||||
scope := g.file.scope.innermost(expr.pos().pos)
|
||||
if expr is ast.Ident {
|
||||
if v := scope.find_var(expr.name) {
|
||||
if v.smartcasts.len > 0 {
|
||||
if v.smartcasts.len > 0 && unwrapped_expected_type == v.orig_type {
|
||||
is_already_sum_type = true
|
||||
}
|
||||
}
|
||||
|
@ -1594,6 +1594,23 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
|
||||
if is_variadic && i == expected_types.len - 1 {
|
||||
break
|
||||
}
|
||||
if arg.expr is ast.Ident {
|
||||
if arg.expr.obj is ast.Var {
|
||||
if arg.expr.obj.smartcasts.len > 0 {
|
||||
exp_sym := g.table.sym(expected_types[i])
|
||||
orig_sym := g.table.sym(arg.expr.obj.orig_type)
|
||||
if orig_sym.kind != .interface_ && (exp_sym.kind != .sum_type
|
||||
|| (exp_sym.kind == .sum_type
|
||||
&& expected_types[i] != arg.expr.obj.orig_type)) {
|
||||
expected_types[i] = g.unwrap_generic(arg.expr.obj.smartcasts.last())
|
||||
cast_sym := g.table.sym(expected_types[i])
|
||||
if cast_sym.info is ast.Aggregate {
|
||||
expected_types[i] = cast_sym.info.types[g.aggregate_type_idx]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
use_tmp_var_autofree := g.is_autofree && arg.typ == ast.string_type && arg.is_tmp_autofree
|
||||
&& !g.inside_const && !g.is_builtin_mod
|
||||
// g.write('/* af=$arg.is_tmp_autofree */')
|
||||
|
@ -0,0 +1,25 @@
|
||||
struct Foo {}
|
||||
|
||||
type Bar = Foo | int
|
||||
type Baz = Foo | f32
|
||||
|
||||
fn foo(a Bar) int {
|
||||
return 22
|
||||
}
|
||||
|
||||
fn bar() Baz {
|
||||
return Foo{}
|
||||
}
|
||||
|
||||
fn test_passing_sumtype_parameter_in_sumtype_matching_results() {
|
||||
a := bar()
|
||||
mut ret := 0
|
||||
match a {
|
||||
Foo {
|
||||
ret = foo(Bar(a))
|
||||
}
|
||||
f32 {}
|
||||
}
|
||||
println(ret)
|
||||
assert ret == 22
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user