@@ -801,18 +801,18 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
801
801
continue
802
802
}
803
803
804
- typ := c.check_expr_opt_call (call_arg.expr, c.expr (call_arg.expr))
805
- node.args[i].typ = typ
804
+ arg_typ := c.check_expr_opt_call (call_arg.expr, c.expr (call_arg.expr))
805
+ node.args[i].typ = arg_typ
806
806
if c.inside_comptime_for_field {
807
807
if mut call_arg.expr is ast.Ident {
808
808
if mut call_arg.expr.obj is ast.Var {
809
809
node.args[i].typ = call_arg.expr.obj.typ
810
810
}
811
811
}
812
812
}
813
- typ_sym := c.table.sym (typ )
813
+ arg_typ_sym := c.table.sym (arg_typ )
814
814
param_typ_sym := c.table.sym (param.typ)
815
- if func.is_variadic && typ .has_flag (.variadic) && node.args.len - 1 > i {
815
+ if func.is_variadic && arg_typ .has_flag (.variadic) && node.args.len - 1 > i {
816
816
c.error ('when forwarding a variadic variable, it must be the final argument' ,
817
817
call_arg.pos)
818
818
}
@@ -846,7 +846,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
846
846
c.error ('function `$node.name ` parameter `$param.name ` is `$tok `, so use `$tok $call_arg.expr ` instead' ,
847
847
call_arg.expr.pos ())
848
848
} else {
849
- c.fail_if_unreadable (call_arg.expr, typ , 'argument' )
849
+ c.fail_if_unreadable (call_arg.expr, arg_typ , 'argument' )
850
850
}
851
851
}
852
852
mut final_param_sym := param_typ_sym
@@ -871,22 +871,23 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
871
871
}
872
872
// Handle expected interface
873
873
if final_param_sym.kind == .interface_ {
874
- if c.type_implements (typ , final_param_typ, call_arg.expr.pos ()) {
875
- if ! typ .is_ptr () && ! typ .is_pointer () && ! c.inside_unsafe
876
- && typ_sym .kind != .interface_ {
874
+ if c.type_implements (arg_typ , final_param_typ, call_arg.expr.pos ()) {
875
+ if ! arg_typ .is_ptr () && ! arg_typ .is_pointer () && ! c.inside_unsafe
876
+ && arg_typ_sym .kind != .interface_ {
877
877
c.mark_as_referenced (mut & call_arg.expr, true )
878
878
}
879
879
}
880
880
continue
881
881
}
882
- c.check_expected_call_arg (typ, c.unwrap_generic (param.typ), node.language, call_arg) or {
882
+ c.check_expected_call_arg (arg_typ, c.unwrap_generic (param.typ), node.language,
883
+ call_arg) or {
883
884
// str method, allow type with str method if fn arg is string
884
885
// Passing an int or a string array produces a c error here
885
886
// Deleting this condition results in propper V error messages
886
887
// if arg_typ_sym.kind == .string && typ_sym.has_method('str') {
887
888
// continue
888
889
// }
889
- if typ_sym .kind == .void && param_typ_sym.kind == .string {
890
+ if arg_typ_sym .kind == .void && param_typ_sym.kind == .string {
890
891
continue
891
892
}
892
893
if param.typ.has_flag (.generic) {
@@ -895,10 +896,10 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
895
896
if c.pref.translated || c.file.is_translated {
896
897
// TODO duplicated logic in check_types() (check_types.v)
897
898
// Allow enums to be used as ints and vice versa in translated code
898
- if param.typ == ast.int_type && typ_sym .kind == .enum_ {
899
+ if param.typ == ast.int_type && arg_typ_sym .kind == .enum_ {
899
900
continue
900
901
}
901
- if typ == ast.int_type && param_typ_sym.kind == .enum_ {
902
+ if arg_typ == ast.int_type && param_typ_sym.kind == .enum_ {
902
903
continue
903
904
}
904
905
// In C unsafe number casts are used all the time (e.g. `char*` where
@@ -907,35 +908,39 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
907
908
if param.typ.is_ptr () {
908
909
param_is_number = param.typ.deref ().is_number ()
909
910
}
910
- mut typ_is_number := typ .is_number ()
911
- if typ .is_ptr () {
912
- typ_is_number = typ .deref ().is_number ()
911
+ mut typ_is_number := arg_typ .is_number ()
912
+ if arg_typ .is_ptr () {
913
+ typ_is_number = arg_typ .deref ().is_number ()
913
914
}
914
915
if param_is_number && typ_is_number {
915
916
continue
916
917
}
917
918
// Allow voidptrs for everything
918
- if param.typ == ast.voidptr_type_idx || typ == ast.voidptr_type_idx {
919
+ if param.typ == ast.voidptr_type_idx || arg_typ == ast.voidptr_type_idx {
919
920
continue
920
921
}
921
922
// Allow `[32]i8` as `&i8` etc
922
- if (typ_sym .kind == .array_fixed && param_is_number)
923
+ if (arg_typ_sym .kind == .array_fixed && param_is_number)
923
924
|| (param_typ_sym.kind == .array_fixed && typ_is_number) {
924
925
continue
925
926
}
926
927
// Allow `int` as `&i8`
927
928
if param.typ.is_any_kind_of_pointer () && typ_is_number {
928
929
continue
929
930
}
931
+ // Allow `&i8` as `int`
932
+ if arg_typ.is_any_kind_of_pointer () && param_is_number {
933
+ continue
934
+ }
930
935
}
931
936
c.error ('$err.msg () in argument ${i + 1} to `$fn_name `' , call_arg.pos)
932
937
}
933
938
// Warn about automatic (de)referencing, which will be removed soon.
934
- if func.language != .c && ! c.inside_unsafe && typ .nr_muls () != param.typ.nr_muls ()
939
+ if func.language != .c && ! c.inside_unsafe && arg_typ .nr_muls () != param.typ.nr_muls ()
935
940
&& ! (call_arg.is_mut && param.is_mut) && ! (! call_arg.is_mut && ! param.is_mut)
936
941
&& param.typ ! in [ast.byteptr_type, ast.charptr_type, ast.voidptr_type] {
937
942
// sym := c.table.sym(typ)
938
- c.warn ('automatic referencing/dereferencing is deprecated and will be removed soon (got: $typ .nr_muls () references, expected: $param.typ.nr_muls () references)' ,
943
+ c.warn ('automatic referencing/dereferencing is deprecated and will be removed soon (got: $arg_typ .nr_muls () references, expected: $param.typ.nr_muls () references)' ,
939
944
call_arg.pos)
940
945
}
941
946
}
0 commit comments