aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-08-17 17:12:27 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2024-08-17 17:12:27 +0200
commitebbb70f11d0fdbe67a15976d2a1be1e2389493fa (patch)
treee2513ffe8887920d7ac6a881cc39c79f484c546a /src/check_type.cpp
parent478f5297449a724a430c569bb0f4a4ff94fb2a77 (diff)
Error if missing map key type
Fixes #4096
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index cbee1d2bd..83b6600c8 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -2741,6 +2741,18 @@ gb_internal void check_map_type(CheckerContext *ctx, Type *type, Ast *node) {
GB_ASSERT(type->kind == Type_Map);
ast_node(mt, MapType, node);
+ if (mt->key == NULL) {
+ if (mt->value != NULL) {
+ Type *value = check_type(ctx, mt->value);
+ gbString str = type_to_string(value);
+ error(node, "Missing map key type, got 'map[]%s'", str);
+ gb_string_free(str);
+ return;
+ }
+ error(node, "Missing map key type, got 'map[]T'");
+ return;
+ }
+
Type *key = check_type(ctx, mt->key);
Type *value = check_type(ctx, mt->value);