aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2025-02-22 17:50:37 +0000
committergingerBill <bill@gingerbill.org>2025-02-22 17:50:37 +0000
commit5bd43b94ec9bf70194ebe7c15bc51a93d135d51d (patch)
treefa843f1ee15ce00e0eccd308d4d120bd586e514c /src
parent748a771dad72c912b48ad2601e459078c7fd1db7 (diff)
Improve error message for matrices with no rows or columns
Diffstat (limited to 'src')
-rw-r--r--src/check_type.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 4d9101c6c..9d4defbb2 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -2859,15 +2859,23 @@ gb_internal void check_matrix_type(CheckerContext *ctx, Type **type, Ast *node)
}
if (generic_row == nullptr && row_count < MATRIX_ELEMENT_COUNT_MIN) {
- gbString s = expr_to_string(row.expr);
- error(row.expr, "Invalid matrix row count, expected %d+ rows, got %s", MATRIX_ELEMENT_COUNT_MIN, s);
- gb_string_free(s);
+ if (row.expr == nullptr) {
+ error(node, "Invalid matrix row count, got nothing");
+ } else {
+ gbString s = expr_to_string(row.expr);
+ error(row.expr, "Invalid matrix row count, expected %d+ rows, got %s", MATRIX_ELEMENT_COUNT_MIN, s);
+ gb_string_free(s);
+ }
}
if (generic_column == nullptr && column_count < MATRIX_ELEMENT_COUNT_MIN) {
- gbString s = expr_to_string(column.expr);
- error(column.expr, "Invalid matrix column count, expected %d+ rows, got %s", MATRIX_ELEMENT_COUNT_MIN, s);
- gb_string_free(s);
+ if (column.expr == nullptr) {
+ error(node, "Invalid matrix column count, got nothing");
+ } else {
+ gbString s = expr_to_string(column.expr);
+ error(column.expr, "Invalid matrix column count, expected %d+ rows, got %s", MATRIX_ELEMENT_COUNT_MIN, s);
+ gb_string_free(s);
+ }
}
if ((generic_row == nullptr && generic_column == nullptr) && row_count*column_count > MATRIX_ELEMENT_COUNT_MAX) {