diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 8302f4bba0..8f9e6b7604 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -298,11 +298,18 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr) } // need to return `array_xxx` instead of `array` method_call_expr.return_type = typ + if name == 'clone' { + method_call_expr.receiver_type = table.type_to_ptr(typ) + } + else { + method_call_expr.receiver_type = typ + } return typ } else if typ_sym.kind == .array && name in ['first', 'last'] { info := typ_sym.info as table.Array method_call_expr.return_type = info.elem_type + method_call_expr.receiver_type = typ return info.elem_type } if method := c.table.type_find_method(typ_sym, name) { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 05be9a5b00..a297a7adc8 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -688,7 +688,15 @@ fn (g mut Gen) expr(node ast.Expr) { } ast.EnumVal { // g.write('/*EnumVal*/${it.mod}${it.enum_name}_$it.val') - g.write(g.typ(it.typ)) + styp := g.typ(it.typ) + if table.type_is_optional(it.typ) { + ostyp := styp + '_$it.val' + if !(ostyp in g.optionals) { + g.definitions.writeln('typedef Option $ostyp;') + g.optionals << ostyp + } + } + g.write(styp) g.write('_$it.val') } ast.FloatLiteral { @@ -743,7 +751,7 @@ fn (g mut Gen) expr(node ast.Expr) { if it.expr_type == 0 { verror('method receiver type is 0, this means there are some uchecked exprs') } - typ_sym := g.table.get_type_symbol(it.expr_type) + typ_sym := g.table.get_type_symbol(it.receiver_type) // rec_sym := g.table.get_type_symbol(it.receiver_type) mut receiver_name := typ_sym.name if typ_sym.kind == .array && it.name in