Skip to content

Commit 9b33ece

Browse files
author
Nathan Hawes
authored
Merge pull request swiftlang#28605 from nathawes/fix-unreachable-in-addSameTypeRequirementBetweenConcrete-during-completion
[AST] Handle visiting UnresolvedType in TypeMatcher
2 parents b890bcb + 12529fe commit 9b33ece

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

include/swift/AST/CanTypeVisitor.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ class CanTypeVisitor {
3131
public:
3232
RetTy visit(CanType T, Args... args) {
3333
switch (T->getKind()) {
34-
#define UNCHECKED_TYPE(CLASS, PARENT) \
35-
case TypeKind::CLASS:
3634
#define SUGARED_TYPE(CLASS, PARENT) \
3735
case TypeKind::CLASS:
3836
#define TYPE(CLASS, PARENT)
3937
#include "swift/AST/TypeNodes.def"
40-
llvm_unreachable("non-canonical or unchecked type");
38+
llvm_unreachable("non-canonical type");
4139

42-
#define UNCHECKED_TYPE(CLASS, PARENT)
4340
#define SUGARED_TYPE(CLASS, PARENT)
4441
#define TYPE(CLASS, PARENT) \
4542
case TypeKind::CLASS: \
@@ -64,7 +61,12 @@ class CanTypeVisitor {
6461
#define TYPE(CLASS, PARENT) ABSTRACT_TYPE(CLASS, PARENT)
6562
#define ABSTRACT_SUGARED_TYPE(CLASS, PARENT)
6663
#define SUGARED_TYPE(CLASS, PARENT)
67-
#define UNCHECKED_TYPE(CLASS, PARENT)
64+
// Don't allow unchecked types by default, but allow visitors to opt-in to
65+
// handling them.
66+
#define UNCHECKED_TYPE(CLASS, PARENT) \
67+
RetTy visit##CLASS##Type(Can##CLASS##Type T, Args... args) { \
68+
llvm_unreachable("unchecked type"); \
69+
}
6870
#include "swift/AST/TypeNodes.def"
6971
};
7072

include/swift/AST/TypeMatcher.h

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ class TypeMatcher {
111111
TRIVIAL_CASE(BuiltinVectorType)
112112
TRIVIAL_CASE(SILTokenType)
113113

114+
bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType,
115+
Type sugaredFirstType) {
116+
// Unresolved types never match.
117+
return mismatch(firstType.getPointer(), secondType, \
118+
sugaredFirstType); \
119+
}
120+
114121
bool visitTupleType(CanTupleType firstTuple, Type secondType,
115122
Type sugaredFirstType) {
116123
if (auto secondTuple = secondType->getAs<TupleType>()) {
@@ -264,23 +271,6 @@ class TypeMatcher {
264271
return mismatch(firstInOut.getPointer(), secondType, sugaredFirstType);
265272
}
266273

267-
bool visitUnboundBoundGenericType(CanUnboundGenericType firstUBGT,
268-
Type secondType, Type sugaredFirstType) {
269-
if (auto secondUBGT = secondType->getAs<UnboundGenericType>()) {
270-
if (firstUBGT->getDecl() != secondUBGT->getDecl())
271-
return mismatch(firstUBGT.getPointer(), secondUBGT, sugaredFirstType);
272-
273-
if (firstUBGT.getParent())
274-
return this->visit(firstUBGT.getParent(), secondUBGT->getParent(),
275-
sugaredFirstType->castTo<UnboundGenericType>()
276-
->getParent());
277-
278-
return true;
279-
}
280-
281-
return mismatch(firstUBGT.getPointer(), secondType, sugaredFirstType);
282-
}
283-
284274
bool visitBoundGenericType(CanBoundGenericType firstBGT,
285275
Type secondType, Type sugaredFirstType) {
286276
auto _secondBGT = secondType->getCanonicalType();
@@ -309,8 +299,6 @@ class TypeMatcher {
309299
return mismatch(firstBGT.getPointer(), secondType, sugaredFirstType);
310300
}
311301

312-
TRIVIAL_CASE(TypeVariableType)
313-
314302
#undef TRIVIAL_CASE
315303
};
316304

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNINFERRED | %FileCheck %s -check-prefix=UNINFERRED
2+
3+
struct S1<V0> {}
4+
protocol P1 {
5+
associatedtype A1
6+
}
7+
extension P1 where A1 == S1<Int> {
8+
subscript<T>(v0: T) -> Int { fatalError() }
9+
subscript<T>(v0: T) -> Undefined { fatalError() }
10+
}
11+
struct S2<T> : P1 {
12+
typealias A1 = S1<T>
13+
}
14+
_ = S2()#^UNINFERRED^#
15+
16+
// UNINFERRED: Decl[Subscript]/Super: [{#(v0): T#}][#Int#]; name=[v0: T]
17+
// UNINFERRED: Decl[Subscript]/Super: [{#(v0): T#}][#<<error type>>#]; name=[v0: T]
18+
// UNINFERRED: Keyword[self]/CurrNominal: .self[#S2<_>#]; name=self

0 commit comments

Comments
 (0)