diff options
| author | gingerBill <bill@gingerbill.org> | 2024-07-22 20:11:23 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-07-22 20:11:23 +0100 |
| commit | ef84382f23920cfd011529db9acd63947bd40b9c (patch) | |
| tree | 85f79b8ac6734127babc8cc79aee3f9bd74b9f07 /src/check_type.cpp | |
| parent | 9cad8179b77a47ad78976ad687e93a8872cbd393 (diff) | |
Add suggestion for #3961
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 22b77db3c..428fe8451 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1559,11 +1559,30 @@ gb_internal Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *pol return poly_type; } if (show_error) { + ERROR_BLOCK(); gbString pts = type_to_string(poly_type); gbString ots = type_to_string(operand.type, true); defer (gb_string_free(pts)); defer (gb_string_free(ots)); 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; } |