Skip to content

Commit 6d7d1d7

Browse files
authored
Merge pull request #84695 from hamishknight/typewriter
[AST] Canonicalize original type for ErrorType
2 parents 79ffee8 + 7465928 commit 6d7d1d7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,9 +1668,10 @@ class ErrorType final : public TypeBase {
16681668
return props;
16691669
}
16701670

1671-
// The Error type is always canonical.
16721671
ErrorType(ASTContext &C, Type originalType)
1673-
: TypeBase(TypeKind::Error, &C, getProperties(originalType)) {
1672+
: TypeBase(TypeKind::Error,
1673+
(!originalType || originalType->isCanonical()) ? &C : nullptr,
1674+
getProperties(originalType)) {
16741675
if (originalType) {
16751676
Bits.ErrorType.HasOriginalType = true;
16761677
*reinterpret_cast<Type *>(this + 1) = originalType;

lib/AST/Type.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,6 @@ CanType TypeBase::computeCanonicalType() {
17651765
#define ALWAYS_CANONICAL_TYPE(id, parent) case TypeKind::id:
17661766
#define TYPE(id, parent)
17671767
#include "swift/AST/TypeNodes.def"
1768-
case TypeKind::Error:
17691768
case TypeKind::TypeVariable:
17701769
case TypeKind::Placeholder:
17711770
case TypeKind::BuiltinTuple:
@@ -1779,6 +1778,14 @@ CanType TypeBase::computeCanonicalType() {
17791778
#define TYPE(id, parent)
17801779
#include "swift/AST/TypeNodes.def"
17811780

1781+
case TypeKind::Error: {
1782+
auto errTy = cast<ErrorType>(this);
1783+
auto originalTy = errTy->getOriginalType();
1784+
ASSERT(originalTy && "The bare ErrorType singleton is already canonical");
1785+
Result = ErrorType::get(originalTy->getCanonicalType()).getPointer();
1786+
break;
1787+
}
1788+
17821789
case TypeKind::Enum:
17831790
case TypeKind::Struct:
17841791
case TypeKind::Class:

test/Constraints/tuple_arguments.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ do {
17281728
do {
17291729
func f(_: Int...) {}
17301730
let _ = [(1, 2, 3)].map(f) // expected-error {{no exact matches in call to instance method 'map'}}
1731-
// expected-note@-1 2{{found candidate with type '(((Int, Int, Int)) -> T) -> [T]'}}
1731+
// expected-note@-1 {{found candidate with type '(((Int, Int, Int)) -> T) -> [T]'}}
17321732
}
17331733

17341734
// rdar://problem/48443263 - cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'

0 commit comments

Comments
 (0)