summaryrefslogtreecommitdiffstats
path: root/source/slang/check.cpp
diff options
context:
space:
mode:
authorYONGH\yongh <yonghe@outlook.com>2017-11-02 19:21:15 -0400
committerYONGH\yongh <yonghe@outlook.com>2017-11-02 19:21:15 -0400
commitd5e2319c33115d0241dd9d2047c0a5f029553dde (patch)
treeb89aef27f2330e7c568b0f799f0902015fdd4f18 /source/slang/check.cpp
parente2b97607977977fd2dbe298c2bb4512f4715dd4c (diff)
work inprogress
Diffstat (limited to 'source/slang/check.cpp')
-rw-r--r--source/slang/check.cpp53
1 files changed, 33 insertions, 20 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 2f4ed2ce8..dc4e48545 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -169,23 +169,18 @@ namespace Slang
sexpr->declRef = declRef;
expr = sexpr;
}
- if (auto assocTypeDeclRef = declRef.As<AssocTypeDecl>())
+ if (auto constraintType = expr->type->As<GenericConstraintDeclRefType>())
{
- if (auto genConstraintType = baseExpr->type->As<GenericConstraintDeclRefType>())
- {
- // if this is a reference from a generic parameter, we need to generate a AssocTypeDeclRefType type.
- // for example, if we have an expression T.U where T:ISimple, and U is an associated type defined in ISimple.
- // then this expression should evaluate to AssocTypeDeclRefType(T, U).
- auto assocTypeDeclType = new AssocTypeDeclRefType();
- assocTypeDeclType->declRef = assocTypeDeclRef;
- assocTypeDeclType->sourceType = genConstraintType->subType;
- assocTypeDeclType->setSession(getSession());
- expr->type = QualType(getTypeType(assocTypeDeclType));
- }
+ if (baseExpr->type->As<TypeType>())
+ constraintType->subType = baseExpr->type->As<TypeType>()->type;
+ else
+ constraintType->subType = baseExpr->type;
+
}
- else if (auto funcDeclRef = declRef.As<CallableDecl>())
+
+ if (auto genConstraintType = baseExpr->type->As<GenericConstraintDeclRefType>())
{
- if (auto genConstraintType = baseExpr->type->As<GenericConstraintDeclRefType>())
+ if (auto funcDeclRef = declRef.As<CallableDecl>())
{
// if this is call expression, propagate the source associated type to the result type
auto funcType = expr->type->As<FuncType>();
@@ -201,9 +196,24 @@ namespace Slang
newFuncType->setSession(funcType->getSession());
expr->type = QualType(newFuncType);
}
-
+ }
+ else if (auto assocTypeDeclRef = declRef.As<AssocTypeDecl>())
+ {
+ auto assocTypeDeclType = new AssocTypeDeclRefType();
+ assocTypeDeclType->declRef = assocTypeDeclRef;
+ assocTypeDeclType->sourceType = genConstraintType->subType;
+ assocTypeDeclType->setSession(getSession());
+ expr->type = QualType(getTypeType(assocTypeDeclType));
}
}
+ else if (auto assocTypeDeclRef = declRef.As<AssocTypeDecl>())
+ {
+ auto assocTypeDeclType = new AssocTypeDeclRefType();
+ assocTypeDeclType->declRef = assocTypeDeclRef;
+ assocTypeDeclType->sourceType = baseExpr->type;
+ assocTypeDeclType->setSession(getSession());
+ expr->type = QualType(getTypeType(assocTypeDeclType));
+ }
return expr;
}
else
@@ -1262,6 +1272,14 @@ namespace Slang
checkDecl(genericDecl->inner);
}
+ void visitGenericTypeConstraintDecl(GenericTypeConstraintDecl * genericConstraintDecl)
+ {
+ // check the type being inherited from
+ auto base = genericConstraintDecl->sup;
+ base = TranslateTypeNode(base);
+ genericConstraintDecl->sup = base;
+ }
+
void visitInheritanceDecl(InheritanceDecl* inheritanceDecl)
{
// check the type being inherited from
@@ -1325,11 +1343,6 @@ namespace Slang
// These are only used in the stdlib, so no checking is needed for now
}
- void visitGenericTypeConstraintDecl(GenericTypeConstraintDecl*)
- {
- // These are only used in the stdlib, so no checking is needed for now
- }
-
void visitModifier(Modifier*)
{
// Do nothing with modifiers for now