diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f7c3697168..e3dc2e2ee2 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1271,10 +1271,13 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type { c.error('cannot cast `$expr_type_sym.name` to `$type_sym.name`', it.pos) // c.error('only $info.variants can be casted to `$typ`', it.pos) } - } else { + } + // + else { c.error('cannot cast non sum type `$type_sym.name` using `as`', it.pos) } - return it.typ + return it.typ.to_ptr() + //return it.typ } ast.AssignExpr { c.assign_expr(mut it) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 8145429d24..8375788057 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1993,7 +1993,7 @@ fn (mut g Gen) const_decl_simple_define(name, val string) { } fn (mut g Gen) struct_init(struct_init ast.StructInit) { - mut info := table.Struct{} + mut info := &table.Struct{} mut is_struct := false sym := g.table.get_type_symbol(struct_init.typ) if sym.kind == .struct_ { @@ -2977,17 +2977,25 @@ fn (mut g Gen) as_cast(node ast.AsCast) { g.expr(node.expr) g.write('.obj') */ - g.write('/* as */ *($styp*)__as_cast(') + dot := if node.expr_type.is_ptr() { '->' } else { '.' } + g.write('/* as */ ($styp*)__as_cast(') g.expr(node.expr) - g.write('.obj, ') + g.write(dot) + g.write('obj, ') g.expr(node.expr) - g.write('.typ, /*expected:*/$node.typ)') + g.write(dot) + g.write('typ, /*expected:*/$node.typ)') } } fn (mut g Gen) is_expr(node ast.InfixExpr) { g.expr(node.left) - g.write('.typ == ') + if node.left_type.is_ptr() { + g.write('->') + } else { + g.write('.') + } + g.write('typ == ') g.expr(node.right) }