@@ -1196,8 +1196,7 @@ fn (mut g Gen) closure_inherited_var_type(node ast.AnonFn, var ast.Param) ast.Ty
11961196 if scope_var := node.decl.scope.parent.find_var (var.name) {
11971197 // If the scope variable has smartcasts and is a sumtype, use the
11981198 // smartcast variant type instead of the original sumtype.
1199- if scope_var.smartcasts.len > 0
1200- && g.table.type_kind (scope_var.typ) == .sum_type {
1199+ if scope_var.smartcasts.len > 0 && g.table.type_kind (scope_var.typ) == .sum_type {
12011200 return g.unwrap_generic (g.recheck_concrete_type (scope_var.smartcasts.last ()))
12021201 }
12031202 // Only use resolved_expr_type for generic type resolution.
@@ -2083,8 +2082,8 @@ fn (mut g Gen) resolve_return_type(node ast.CallExpr) ast.Type {
20832082 return_type.clear_option_and_result ()
20842083 }
20852084 }
2086- if final_left_sym.kind == .array && ! (left_sym.kind == .alias
2087- && left_sym.has_method (node.name)) && (node.name == 'get'
2085+ if final_left_sym.kind == .array && ! (left_sym.has_method (node.name)
2086+ || left_sym.has_method_with_generic_parent (node.name)) && (node.name == 'get'
20882087 || node.kind in [.first, .last, .pop_left, .pop, .map , .filter, .reverse, .clone, .clone_to_depth, .repeat, .trim, .slice, .sorted, .sorted_with_compare]) {
20892088 return_type := g.resolved_array_builtin_method_return_type (node, left_type,
20902089 node.return_type)
@@ -2157,6 +2156,7 @@ fn (mut g Gen) resolve_return_type(node ast.CallExpr) ast.Type {
21572156 continue
21582157 }
21592158 slot := rec_len + generic_arg_idx
2159+ generic_arg_idx++
21602160 mut resolved_arg_type := ast.void_type
21612161 if arg.expr is ast.Ident && arg.expr.obj is ast.Var
21622162 && (arg.expr.obj as ast.Var ).ct_type_var == .generic_param {
@@ -2173,13 +2173,15 @@ fn (mut g Gen) resolve_return_type(node ast.CallExpr) ast.Type {
21732173 && ! param.typ.is_ptr () {
21742174 resolved_arg_type = resolved_arg_type.deref ()
21752175 }
2176+ if resolved_arg_type.clear_option_and_result () == ast.none_type {
2177+ continue
2178+ }
21762179 if resolved_arg_type != 0 && resolved_arg_type != ast.void_type
21772180 && ! resolved_arg_type.has_flag (.generic)
21782181 && ! g.type_has_unresolved_generic_parts (resolved_arg_type)
21792182 && slot < concrete_types.len {
21802183 concrete_types[slot] = resolved_arg_type
21812184 }
2182- generic_arg_idx++
21832185 }
21842186 }
21852187
@@ -2437,8 +2439,7 @@ fn (mut g Gen) resolved_generic_call_arg_type(arg ast.CallArg) ast.Type {
24372439 // In comptime variant loops, a smartcast variable's type is dynamically
24382440 // resolved per variant iteration. Don't override it with the generic param
24392441 // resolution (which gives the sumtype, not the variant).
2440- is_comptime_smartcast := arg.expr.obj is ast.Var
2441- && arg.expr.obj.ct_type_var == .smartcast
2442+ is_comptime_smartcast := arg.expr.obj is ast.Var && arg.expr.obj.ct_type_var == .smartcast
24422443 && g.comptime.comptime_for_variant_var.len > 0
24432444 if ! is_comptime_smartcast {
24442445 resolved_current_type = g.resolve_current_fn_generic_param_type (arg.expr.name)
@@ -3162,16 +3163,17 @@ fn (mut g Gen) unwrap_receiver_type(node ast.CallExpr) (ast.Type, &ast.TypeSymbo
31623163 if g.cur_fn != unsafe { nil } && g.cur_concrete_types.len > 0 {
31633164 left_sym2 := g.table.sym (left_type)
31643165 if ! left_sym2 .has_method (node.name) {
3165- _ , embed_types := g.table.find_method_from_embeds (left_sym2 ,
3166- node.name) or { ast.Fn{}, []ast.Type{} }
3166+ _ , embed_types := g.table.find_method_from_embeds (left_sym2 , node.name) or {
3167+ ast.Fn{}, []ast.Type{}
3168+ }
31673169 if embed_types.len > 0 {
31683170 unwrapped_rec_type = embed_types.last ()
31693171 typ_sym = g.table.sym (unwrapped_rec_type)
31703172 }
31713173 } else if left_type != unwrapped_rec_type {
31723174 // left_type has the method directly; use it instead of stale receiver type
31733175 unwrapped_rec_type = left_type
3174- typ_sym = left_sym 2
3176+ typ_sym = g.table. sym (unwrapped_rec_type)
31753177 }
31763178 } else if node.from_embed_types.len > 0 && ! typ_sym.has_method (node.name) {
31773179 unwrapped_rec_type = node.from_embed_types.last ()
@@ -3345,8 +3347,9 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
33453347 use_builtin_array_sort = method.params.len == 1
33463348 }
33473349 }
3348- if final_left_sym.kind == .array
3349- && (! (left_sym.has_method (method_name)) || use_builtin_array_sort || method_name == 'get' ) {
3350+ if final_left_sym.kind == .array && (! (left_sym.has_method (method_name)
3351+ || left_sym.has_method_with_generic_parent (method_name))
3352+ || use_builtin_array_sort) {
33503353 if g.gen_array_method_call (node, left_type, final_left_sym) {
33513354 return
33523355 }
@@ -4286,8 +4289,8 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
42864289 mut print_arg_typ := if is_print && node.args.len > 0 { node.args[0 ].typ } else { ast.void_type }
42874290 // In generic contexts, AST-stored types may be stale from a previous
42884291 // instantiation. Use resolved_expr_type for Ident expressions.
4289- if is_print && node.args.len > 0 && g.cur_fn != unsafe { nil }
4290- && g.cur_concrete_types.len > 0 && node.args[0 ].expr is ast.Ident {
4292+ if is_print && node.args.len > 0 && g.cur_fn != unsafe { nil } && g.cur_concrete_types.len > 0
4293+ && node.args[0 ].expr is ast.Ident {
42914294 resolved := g.resolved_expr_type (node.args[0 ].expr, node.args[0 ].typ)
42924295 if resolved != 0 {
42934296 print_arg_typ = resolved
0 commit comments