Skip to content

Commit 00b540b

Browse files
authored
Merge pull request #7967 from jrose-apple/3.1-to-err-is-human
Make sure ErrorTypes containing type variables are marked as such
2 parents ce937d9 + 601c968 commit 00b540b

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

include/swift/AST/Types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,10 @@ class alignas(1 << TypeAlignInBits) TypeBase {
992992
class ErrorType : public TypeBase {
993993
friend class ASTContext;
994994
// The Error type is always canonical.
995-
ErrorType(ASTContext &C, Type originalType)
996-
: TypeBase(TypeKind::Error, &C, RecursiveTypeProperties::HasError) {
995+
ErrorType(ASTContext &C, Type originalType,
996+
RecursiveTypeProperties properties)
997+
: TypeBase(TypeKind::Error, &C, properties) {
998+
assert(properties.hasError());
997999
if (originalType) {
9981000
ErrorTypeBits.HasOriginalType = true;
9991001
*reinterpret_cast<Type *>(this + 1) = originalType;

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ ASTContext::ASTContext(LangOptions &langOpts, SearchPathOptions &SearchPathOpts,
402402
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
403403
TypeCheckerDebug(new StderrTypeCheckerDebugConsumer()),
404404
TheErrorType(
405-
new (*this, AllocationArena::Permanent) ErrorType(*this, Type())),
405+
new (*this, AllocationArena::Permanent)
406+
ErrorType(*this, Type(), RecursiveTypeProperties::HasError)),
406407
TheUnresolvedType(new (*this, AllocationArena::Permanent)
407408
UnresolvedType(*this)),
408409
TheEmptyTupleType(TupleType::get(ArrayRef<TupleTypeElt>(), *this)),
@@ -2435,16 +2436,19 @@ Type ErrorType::get(const ASTContext &C) { return C.TheErrorType; }
24352436
Type ErrorType::get(Type originalType) {
24362437
assert(originalType);
24372438

2438-
auto properties = originalType->getRecursiveProperties();
2439-
auto arena = getArena(properties);
2439+
auto originalProperties = originalType->getRecursiveProperties();
2440+
auto arena = getArena(originalProperties);
24402441

24412442
auto &ctx = originalType->getASTContext();
24422443
auto &entry = ctx.Impl.getArena(arena).ErrorTypesWithOriginal[originalType];
24432444
if (entry) return entry;
24442445

24452446
void *mem = ctx.Allocate(sizeof(ErrorType) + sizeof(Type),
24462447
alignof(ErrorType), arena);
2447-
return entry = new (mem) ErrorType(ctx, originalType);
2448+
RecursiveTypeProperties properties = RecursiveTypeProperties::HasError;
2449+
if (originalProperties.hasTypeVariable())
2450+
properties |= RecursiveTypeProperties::HasTypeVariable;
2451+
return entry = new (mem) ErrorType(ctx, originalType, properties);
24482452
}
24492453

24502454
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,

lib/AST/Type.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ TypeBase::getTypeVariables(SmallVectorImpl<TypeVariableType *> &typeVariables) {
470470

471471
return false;
472472
});
473-
assert(!typeVariables.empty() && "Did not find type variables!");
473+
assert((!typeVariables.empty() || hasError()) &&
474+
"Did not find type variables!");
474475
}
475476
}
476477

0 commit comments

Comments
 (0)