aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 3262aea5d..cead61ce8 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -686,14 +686,14 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
ast_node(ie, BinaryExpr, expr);
Operand lhs = {};
Operand rhs = {};
- check_expr(ctx, &lhs, ie->left);
+ check_expr_with_type_hint(ctx, &lhs, ie->left, x.type);
if (x.mode == Addressing_Invalid) {
continue;
}
if (lhs.mode == Addressing_Invalid) {
continue;
}
- check_expr(ctx, &rhs, ie->right);
+ check_expr_with_type_hint(ctx, &rhs, ie->right, x.type);
if (rhs.mode == Addressing_Invalid) {
continue;
}
@@ -732,7 +732,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
if (is_type_typeid(x.type)) {
check_expr_or_type(ctx, &y, expr, x.type);
} else {
- check_expr(ctx, &y, expr);
+ check_expr_with_type_hint(ctx, &y, expr, x.type);
}
if (x.mode == Addressing_Invalid ||
@@ -1665,8 +1665,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
if (!is_blank_ident(str)) {
found = scope_lookup_current(ctx->scope, str);
new_name_count += 1;
- } else if (vd->is_static) {
- error(name, "'static' is now allowed to be applied to '_'");
}
if (found == nullptr) {
entity = alloc_entity_variable(ctx->scope, token, nullptr, false);
@@ -1678,9 +1676,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
entity->Variable.is_foreign = true;
entity->Variable.foreign_library_ident = fl;
}
- if (vd->is_static) {
- entity->flags |= EntityFlag_Static;
- }
} else {
TokenPos pos = found->token.pos;
error(token,
@@ -1744,6 +1739,16 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
if (ac.link_name.len > 0) {
e->Variable.link_name = ac.link_name;
}
+
+ e->flags &= ~EntityFlag_Static;
+ if (ac.is_static) {
+ String name = e->token.string;
+ if (name == "_") {
+ error(e->token, "The 'static' attribute is not allowed to be applied to '_'");
+ } else {
+ e->flags |= EntityFlag_Static;
+ }
+ }
}
check_arity_match(ctx, vd);
@@ -1751,6 +1756,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
for (isize i = 0; i < entity_count; i++) {
Entity *e = entities[i];
+
if (e->Variable.is_foreign) {
if (vd->values.count > 0) {
error(e->token, "A foreign variable declaration cannot have a default value");
@@ -1842,6 +1848,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
}
}
}
+
} else {
// constant value declaration
// NOTE(bill): Check `_` declarations