Skip to content

Commit 5495280

Browse files
authored
checker: allow for f() or { T{} } part 2, see also cc55aa5 (handle the case of an ignored result as well) (#22687)
1 parent 5d76ee4 commit 5495280

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

vlib/v/checker/checker.v

+3
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,9 @@ fn (mut c Checker) check_or_last_stmt(mut stmt ast.Stmt, ret_type ast.Type, expr
14721472
return
14731473
}
14741474
}
1475+
if expr_return_type.has_flag(.generic) {
1476+
return
1477+
}
14751478
// opt_returning_string() or { ... 123 }
14761479
type_name := c.table.type_to_str(stmt.typ)
14771480
expr_return_type_name := c.table.type_to_str(expr_return_type)

vlib/v/tests/generics/generic_default_expression_in_or_block_test.v

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn (mut s St[T]) peek_or_default() T {
1616
}
1717

1818
fn (mut s St[T]) push(e T) {
19+
s.peek() or { T{} }
1920
x := s.peek() or { T{} } // this is deliberate
2021
$if x is $array {
2122
dump(x)

0 commit comments

Comments
 (0)