mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Add suggestion for #3961
This commit is contained in:
@@ -1559,11 +1559,30 @@ gb_internal Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *pol
|
|||||||
return poly_type;
|
return poly_type;
|
||||||
}
|
}
|
||||||
if (show_error) {
|
if (show_error) {
|
||||||
|
ERROR_BLOCK();
|
||||||
gbString pts = type_to_string(poly_type);
|
gbString pts = type_to_string(poly_type);
|
||||||
gbString ots = type_to_string(operand.type, true);
|
gbString ots = type_to_string(operand.type, true);
|
||||||
defer (gb_string_free(pts));
|
defer (gb_string_free(pts));
|
||||||
defer (gb_string_free(ots));
|
defer (gb_string_free(ots));
|
||||||
error(operand.expr, "Cannot determine polymorphic type from parameter: '%s' to '%s'", ots, pts);
|
error(operand.expr, "Cannot determine polymorphic type from parameter: '%s' to '%s'", ots, pts);
|
||||||
|
|
||||||
|
Type *pt = poly_type;
|
||||||
|
while (pt && pt->kind == Type_Generic && pt->Generic.specialized) {
|
||||||
|
pt = pt->Generic.specialized;
|
||||||
|
}
|
||||||
|
if (is_type_slice(pt) &&
|
||||||
|
(is_type_dynamic_array(operand.type) || is_type_array(operand.type))) {
|
||||||
|
Ast *expr = unparen_expr(operand.expr);
|
||||||
|
if (expr->kind == Ast_CompoundLit) {
|
||||||
|
gbString es = type_to_string(base_any_array_type(operand.type));
|
||||||
|
error_line("\tSuggestion: Try using a slice compound literal instead '[]%s{...}'\n", es);
|
||||||
|
gb_string_free(es);
|
||||||
|
} else {
|
||||||
|
gbString os = expr_to_string(operand.expr);
|
||||||
|
error_line("\tSuggestion: Try slicing the value with '%s[:]'\n", os);
|
||||||
|
gb_string_free(os);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return t_invalid;
|
return t_invalid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1637,6 +1637,26 @@ gb_internal Type *base_array_type(Type *t) {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gb_internal Type *base_any_array_type(Type *t) {
|
||||||
|
Type *bt = base_type(t);
|
||||||
|
if (is_type_array(bt)) {
|
||||||
|
return bt->Array.elem;
|
||||||
|
} else if (is_type_slice(bt)) {
|
||||||
|
return bt->Slice.elem;
|
||||||
|
} else if (is_type_dynamic_array(bt)) {
|
||||||
|
return bt->DynamicArray.elem;
|
||||||
|
} else if (is_type_enumerated_array(bt)) {
|
||||||
|
return bt->EnumeratedArray.elem;
|
||||||
|
} else if (is_type_simd_vector(bt)) {
|
||||||
|
return bt->SimdVector.elem;
|
||||||
|
} else if (is_type_matrix(bt)) {
|
||||||
|
return bt->Matrix.elem;
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
gb_internal bool is_type_generic(Type *t) {
|
gb_internal bool is_type_generic(Type *t) {
|
||||||
t = base_type(t);
|
t = base_type(t);
|
||||||
return t->kind == Type_Generic;
|
return t->kind == Type_Generic;
|
||||||
|
|||||||
Reference in New Issue
Block a user