aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-04 13:48:52 +0100
committergingerBill <bill@gingerbill.org>2024-07-04 13:48:52 +0100
commit657bc88535eb3b160d86fed5f5e5d0d6ea67c78c (patch)
treee67b19721746e14e0a48a922b62b5935b6ecf883 /src/check_expr.cpp
parent45b2a6a19eb48059566caa9efbf15a8ac644b5ce (diff)
Allow `x :: y when cond else proc(...){...}`
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 2d0b9dfa9..af5a9c521 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -4968,7 +4968,27 @@ gb_internal bool is_entity_declared_for_selector(Entity *entity, Scope *import_s
// NOTE(bill, 2022-02-03): see `check_const_decl` for why it exists reasoning
gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool ident_only) {
- if (node->kind == Ast_Ident) {
+ if (node == nullptr) {
+ return nullptr;
+ }
+ if (node->kind == Ast_TernaryWhenExpr) {
+ ast_node(we, TernaryWhenExpr, node);
+ if (we->cond == nullptr) {
+ return nullptr;
+ }
+ if (we->cond->tav.mode != Addressing_Constant) {
+ return nullptr;
+ }
+ if (we->cond->tav.value.kind != ExactValue_Bool) {
+ return nullptr;
+ }
+ if (we->cond->tav.value.value_bool) {
+ return check_entity_from_ident_or_selector(c, we->x, ident_only);
+ } else {
+ Entity *e = check_entity_from_ident_or_selector(c, we->y, ident_only);
+ return e;
+ }
+ } else if (node->kind == Ast_Ident) {
String name = node->Ident.token.string;
return scope_lookup(c->scope, name);
} else if (!ident_only) if (node->kind == Ast_SelectorExpr) {