1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix call arg type changing on match expr (#16744)

This commit is contained in:
Felipe Pena 2022-12-22 20:58:52 -03:00 committed by GitHub
parent fc5826b7ca
commit b21e5b71ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -1719,8 +1719,7 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
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] != 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 {

View File

@ -0,0 +1,35 @@
struct MotionEvent {}
struct ButtonEvent {}
struct WheelEvent {}
type Event = ButtonEvent | MotionEvent | WheelEvent
type GameEvent = ButtonEvent | MotionEvent
fn test_main() {
be := ButtonEvent{}
assert handle_event(be) == true
e := Event(be)
assert handle_event(e) == true
match e {
MotionEvent {
assert handle_game_event(e) == true
}
ButtonEvent {
assert handle_game_event(e) == true
}
else {}
}
}
fn handle_game_event(ge GameEvent) bool {
is_button_event := ge is ButtonEvent
return is_button_event
}
fn handle_event(e Event) bool {
is_button_event := e is ButtonEvent
return is_button_event
}