Skip to content

Commit 01bb403

Browse files
committed
AST: Prohibit archetypes in setInterfaceType()
1 parent 835472b commit 01bb403

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

lib/AST/Decl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,13 @@ Type ValueDecl::getInterfaceType() const {
17051705
void ValueDecl::setInterfaceType(Type type) {
17061706
assert((type.isNull() || !type->hasTypeVariable()) &&
17071707
"Type variable in interface type");
1708+
1709+
// lldb creates global typealiases with archetypes in them.
1710+
// FIXME: Add an isDebugAlias() flag, like isDebugVar().
1711+
if (!isa<TypeAliasDecl>(this)) {
1712+
assert((type.isNull() || !type->hasArchetype()) &&
1713+
"Archetype in interface type");
1714+
}
17081715

17091716
InterfaceTy = type;
17101717
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,8 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
22832283
Context.getIdentifier("$match"),
22842284
rhsType,
22852285
DC);
2286-
matchVar->setInterfaceType(rhsType);
2286+
matchVar->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext(
2287+
DC, rhsType));
22872288

22882289
matchVar->setImplicit();
22892290
EP->setMatchVar(matchVar);

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ static bool coercePatternViaConditionalDowncast(TypeChecker &tc,
971971
pattern->getLoc(),
972972
tc.Context.getIdentifier("$match"),
973973
type, dc);
974-
matchVar->setInterfaceType(type);
974+
matchVar->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext(dc, type));
975975
matchVar->setHasNonPatternBindingInit();
976976

977977
// Form the cast $match as? T, which produces an optional.

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
664664
generator = new (TC.Context)
665665
VarDecl(/*static*/ false, /*IsLet*/ false, S->getInLoc(),
666666
TC.Context.getIdentifier(name), generatorTy, DC);
667-
generator->setInterfaceType(generatorTy);
667+
generator->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext(
668+
DC, generatorTy));
668669
generator->setImplicit();
669670

670671
// Create a pattern binding to initialize the generator.

lib/Serialization/Serialization.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,12 +2521,15 @@ void Serializer::writeDecl(const Decl *D) {
25212521
verifyAttrSerializable(param);
25222522

25232523
auto contextID = addDeclContextRef(param->getDeclContext());
2524-
Type type = (param->hasType()
2525-
? param->getType()
2526-
: Type());
2527-
Type interfaceType = (param->hasInterfaceType()
2528-
? param->getInterfaceType()
2529-
: Type());
2524+
Type type, interfaceType;
2525+
2526+
if (param->hasType()) {
2527+
type = param->getType();
2528+
interfaceType = param->getInterfaceType();
2529+
// FIXME: Interface types for ParamDecls
2530+
if (interfaceType->hasArchetype())
2531+
interfaceType = Type();
2532+
}
25302533

25312534
unsigned abbrCode = DeclTypeAbbrCodes[ParamLayout::Code];
25322535
ParamLayout::emitRecord(Out, ScratchRecord, abbrCode,

0 commit comments

Comments
 (0)