1
0
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:
Felipe Pena 2023-06-10 12:02:54 -03:00 committed by GitHub
parent c0843af4f7
commit e27786235a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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
}
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_typ.idx() != ret_typ.idx() {
return g.expr_opt_with_cast(expr, expr_typ, ret_typ)

View 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'
})
}