Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 29, 2024
1 parent 4225a34 commit dd75c4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
right_expr := node.right
mut typ := match right_expr {
ast.TypeNode {
right_expr.typ
c.unwrap_generic(right_expr.typ)
}
ast.None {
ast.none_type_idx
Expand Down
20 changes: 20 additions & 0 deletions vlib/v/tests/sumtypes/sumtype_generic_checking_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type Sumtype = string | int

fn generic_fn[T]() ?T {
a := Sumtype('123')
if a is T {
return a
}

b := Sumtype(123)
if b is T {
return b
}

return none
}

fn test_main() {
assert generic_fn[string]().str() == "Option('123')"
assert generic_fn[int]().str() == 'Option(123)'
}

0 comments on commit dd75c4b

Please sign in to comment.