Fix statics [wip]

typecheck-v2
Ibrahim Numanagić 2024-03-04 19:11:22 -08:00
parent 4ae3c5f7ec
commit 0c5e22bf6d
4 changed files with 9 additions and 3 deletions

View File

@ -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<RecordType>(cache, name, name, generics);
}
/*****************************************************************/
IntStaticType::IntStaticType(Cache *cache, int64_t i)

View File

@ -23,6 +23,7 @@ public:
bool isInstantiated() const override;
std::string realizedName() const override;
virtual std::shared_ptr<Expr> getStaticExpr() const = 0;
virtual TypePtr getNonStaticType() const;
std::shared_ptr<StaticType> getStatic() override {
return std::static_pointer_cast<StaticType>(shared_from_this());
}

View File

@ -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);

View File

@ -529,7 +529,10 @@ bool TypecheckVisitor::wrapExpr(ExprPtr &expr, const TypePtr &expectedType,
std::unordered_set<std::string> 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()) {