Fix corner case when typechecking scoped names with static compilation (#392)

* Fix corner case when typechecking scoped names with static compilation

* Undo log

---------

Co-authored-by: Ibrahim Numanagić <ibrahimpasa@gmail.com>
pull/396/head
A. R. Shajii 2023-05-26 17:00:37 -04:00 committed by GitHub
parent 38e08b409a
commit 2b2f6498b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -372,6 +372,10 @@ void TranslateVisitor::visit(AssignStmt *stmt) {
auto isGlobal = in(ctx->cache->globals, var);
ir::Var *v = nullptr;
// dead declaration due to static compilation
if (!stmt->rhs && !stmt->type && !stmt->lhs->type->getClass())
return;
if (isGlobal) {
seqassert(ctx->find(var) && ctx->find(var)->getVar(), "cannot find global '{}'",
var);

View File

@ -64,7 +64,7 @@ void TypecheckVisitor::visit(AssignStmt *stmt) {
ctx->instantiate(stmt->type->getSrcInfo(), stmt->type->getType()));
}
ctx->add(TypecheckItem::Var, lhs, stmt->lhs->type);
if (realize(stmt->lhs->type))
if (realize(stmt->lhs->type) || !stmt->type)
stmt->setDone();
} else if (stmt->type && stmt->type->getType()->isStaticType()) {
// Static assignments (e.g., `x: Static[int] = 5`)

View File

@ -7,6 +7,11 @@ class __internal__:
class __magic__:
pass
@tuple
@__internal__
class NoneType:
pass
@tuple
@__internal__
@__notuple__
@ -40,11 +45,6 @@ class float32:
MIN_10_EXP = -37
pass
@tuple
@__internal__
class NoneType:
pass
@tuple
@__internal__
class type: