mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
Fix statics [wip]
This commit is contained in:
parent
4ae3c5f7ec
commit
0c5e22bf6d
@ -31,6 +31,10 @@ bool StaticType::isInstantiated() const { return true; }
|
|||||||
|
|
||||||
std::string StaticType::realizedName() const { return debugString(0); }
|
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)
|
IntStaticType::IntStaticType(Cache *cache, int64_t i)
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
bool isInstantiated() const override;
|
bool isInstantiated() const override;
|
||||||
std::string realizedName() const override;
|
std::string realizedName() const override;
|
||||||
virtual std::shared_ptr<Expr> getStaticExpr() const = 0;
|
virtual std::shared_ptr<Expr> getStaticExpr() const = 0;
|
||||||
|
virtual TypePtr getNonStaticType() const;
|
||||||
std::shared_ptr<StaticType> getStatic() override {
|
std::shared_ptr<StaticType> getStatic() override {
|
||||||
return std::static_pointer_cast<StaticType>(shared_from_this());
|
return std::static_pointer_cast<StaticType>(shared_from_this());
|
||||||
}
|
}
|
||||||
|
@ -254,8 +254,6 @@ types::TypePtr TypecheckVisitor::realizeType(types::ClassType *type) {
|
|||||||
if (!ftyp->canRealize() && field.typeExpr) {
|
if (!ftyp->canRealize() && field.typeExpr) {
|
||||||
auto t = ctx->getType(transform(clean_clone(field.typeExpr))->type);
|
auto t = ctx->getType(transform(clean_clone(field.typeExpr))->type);
|
||||||
unify(ftyp, t);
|
unify(ftyp, t);
|
||||||
LOG("- {} {} {:c}", realized, clean_clone(field.typeExpr),
|
|
||||||
ftyp);
|
|
||||||
}
|
}
|
||||||
if (!realize(ftyp)) {
|
if (!realize(ftyp)) {
|
||||||
realize(ftyp);
|
realize(ftyp);
|
||||||
|
@ -529,7 +529,10 @@ bool TypecheckVisitor::wrapExpr(ExprPtr &expr, const TypePtr &expectedType,
|
|||||||
|
|
||||||
std::unordered_set<std::string> hints = {"Generator", "float", TYPE_OPTIONAL,
|
std::unordered_set<std::string> hints = {"Generator", "float", TYPE_OPTIONAL,
|
||||||
"pyobj"};
|
"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.
|
return false; // argument type not yet known.
|
||||||
} else if (expectedClass && expectedClass->name == "Generator" &&
|
} else if (expectedClass && expectedClass->name == "Generator" &&
|
||||||
exprClass->name != expectedClass->name && !expr->getEllipsis()) {
|
exprClass->name != expectedClass->name && !expr->getEllipsis()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user