mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix selector option casting (#18395)
This commit is contained in:
parent
c0843af4f7
commit
e27786235a
@ -93,7 +93,7 @@ fn (mut g Gen) expr_with_opt(expr ast.Expr, expr_typ ast.Type, ret_typ ast.Type)
|
|||||||
g.inside_opt_or_res = old_inside_opt_or_res
|
g.inside_opt_or_res = old_inside_opt_or_res
|
||||||
}
|
}
|
||||||
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option)
|
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option)
|
||||||
&& expr in [ast.DumpExpr, ast.Ident, ast.ComptimeSelector, ast.AsCast, ast.CallExpr, ast.MatchExpr, ast.IfExpr, ast.IndexExpr, ast.UnsafeExpr, ast.CastExpr] {
|
&& expr in [ast.SelectorExpr, ast.DumpExpr, ast.Ident, ast.ComptimeSelector, ast.AsCast, ast.CallExpr, ast.MatchExpr, ast.IfExpr, ast.IndexExpr, ast.UnsafeExpr, ast.CastExpr] {
|
||||||
if expr in [ast.Ident, ast.CastExpr] {
|
if expr in [ast.Ident, ast.CastExpr] {
|
||||||
if expr_typ.idx() != ret_typ.idx() {
|
if expr_typ.idx() != ret_typ.idx() {
|
||||||
return g.expr_opt_with_cast(expr, expr_typ, ret_typ)
|
return g.expr_opt_with_cast(expr, expr_typ, ret_typ)
|
||||||
|
15
vlib/v/tests/option_selector_cast_test.v
Normal file
15
vlib/v/tests/option_selector_cast_test.v
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[params]
|
||||||
|
struct ConnectParams {
|
||||||
|
password ?string
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn connect(params ConnectParams) ? {
|
||||||
|
password2 := ?string(params.password)
|
||||||
|
assert password2? == 'foo'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
connect(ConnectParams{
|
||||||
|
password: 'foo'
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user