Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix if cond with alias (fix #17818) #17821

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vlib/v/checker/if.v
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
} else {
// check condition type is boolean
c.expected_type = ast.bool_type
cond_typ := c.unwrap_generic(c.expr(branch.cond))
cond_typ := c.table.unaliased_type(c.unwrap_generic(c.expr(branch.cond)))
if (cond_typ.idx() != ast.bool_type_idx || cond_typ.has_flag(.option)
|| cond_typ.has_flag(.result)) && !c.pref.translated && !c.file.is_translated {
c.error('non-bool type `${c.table.type_to_str(cond_typ)}` used as if condition',
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/tests/if_cond_with_alias_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type BOOL = bool

fn example() BOOL {
return true
}

fn test_if_cond_with_alias() {
if example() {
println('Should work, or not?')
assert true
} else {
assert false
}
}