Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 11, 2025
1 parent 81b421b commit 5e40827
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vlib/v/gen/c/if.v
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
cond.expr_type
}
g.writeln('${g.styp(g.unwrap_generic(cond_expr_type))} ${var_name};')
} else if cond.expr is ast.IndexExpr {
value_type := g.table.value_type(g.unwrap_generic(cond.expr.left_type))
if value_type.has_flag(.option) {
var_name := g.new_tmp_var()
guard_vars[i] = var_name
g.writeln('${g.styp(value_type)} ${var_name};')
} else {
guard_vars[i] = ''
}
} else {
guard_vars[i] = ''
}
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/tests/options/option_ifguard_array_of_option_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module main

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / clang (macos-14)

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / docker-ubuntu-musl

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / msvc

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / gcc

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tcc

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / gcc

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tcc

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / clang

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tests-sanitize-undefined-clang

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tests-sanitize-address-clang

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tests-sanitize-undefined-gcc

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tests-sanitize-memory-clang

a _test.v file should have *at least* one `test_` function

Check failure on line 1 in vlib/v/tests/options/option_ifguard_array_of_option_test.v

View workflow job for this annotation

GitHub Actions / tests-sanitize-address-gcc

a _test.v file should have *at least* one `test_` function

fn make_option() ?string {
return 'abc'
}

fn main() {
cols := [make_option()]
if col := cols[0] {
assert col == 'abc'
assert true
dump(col)
}
}

0 comments on commit 5e40827

Please sign in to comment.