From 0c5e22bf6dba37746a1378cf30d23fea40efdec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ibrahim=20Numanagic=CC=81?= Date: Mon, 4 Mar 2024 19:11:22 -0800 Subject: [PATCH] Fix statics [wip] --- codon/parser/ast/types/static.cpp | 4 ++++ codon/parser/ast/types/static.h | 1 + codon/parser/visitors/typecheck/infer.cpp | 2 -- codon/parser/visitors/typecheck/typecheck.cpp | 5 ++++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/codon/parser/ast/types/static.cpp b/codon/parser/ast/types/static.cpp index 1cb6cacc..efa9b86f 100644 --- a/codon/parser/ast/types/static.cpp +++ b/codon/parser/ast/types/static.cpp @@ -31,6 +31,10 @@ bool StaticType::isInstantiated() const { return true; } std::string StaticType::realizedName() const { return debugString(0); } +TypePtr StaticType::getNonStaticType() const { + return std::make_shared(cache, name, name, generics); +} + /*****************************************************************/ IntStaticType::IntStaticType(Cache *cache, int64_t i) diff --git a/codon/parser/ast/types/static.h b/codon/parser/ast/types/static.h index 2acc3cd5..a3b8ed7c 100644 --- a/codon/parser/ast/types/static.h +++ b/codon/parser/ast/types/static.h @@ -23,6 +23,7 @@ public: bool isInstantiated() const override; std::string realizedName() const override; virtual std::shared_ptr getStaticExpr() const = 0; + virtual TypePtr getNonStaticType() const; std::shared_ptr getStatic() override { return std::static_pointer_cast(shared_from_this()); } diff --git a/codon/parser/visitors/typecheck/infer.cpp b/codon/parser/visitors/typecheck/infer.cpp index 4824dcf5..a5cf05ac 100644 --- a/codon/parser/visitors/typecheck/infer.cpp +++ b/codon/parser/visitors/typecheck/infer.cpp @@ -254,8 +254,6 @@ types::TypePtr TypecheckVisitor::realizeType(types::ClassType *type) { if (!ftyp->canRealize() && field.typeExpr) { auto t = ctx->getType(transform(clean_clone(field.typeExpr))->type); unify(ftyp, t); - LOG("- {} {} {:c}", realized, clean_clone(field.typeExpr), - ftyp); } if (!realize(ftyp)) { realize(ftyp); diff --git a/codon/parser/visitors/typecheck/typecheck.cpp b/codon/parser/visitors/typecheck/typecheck.cpp index a8e6bc58..e69a2c3f 100644 --- a/codon/parser/visitors/typecheck/typecheck.cpp +++ b/codon/parser/visitors/typecheck/typecheck.cpp @@ -529,7 +529,10 @@ bool TypecheckVisitor::wrapExpr(ExprPtr &expr, const TypePtr &expectedType, std::unordered_set hints = {"Generator", "float", TYPE_OPTIONAL, "pyobj"}; - if (!exprClass && expectedClass && in(hints, expectedClass->name)) { + if (expr->type->getStatic() && (!expectedType || !expectedType->isStaticType())) { + expr->type = expr->type->getStatic()->getNonStaticType(); + return false; + } if (!exprClass && expectedClass && in(hints, expectedClass->name)) { return false; // argument type not yet known. } else if (expectedClass && expectedClass->name == "Generator" && exprClass->name != expectedClass->name && !expr->getEllipsis()) {