Skip to content

Commit 3720716

Browse files
committed
More error checking for subscript decls
1 parent bed0da6 commit 3720716

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3371,7 +3371,10 @@ void SubscriptDecl::setIndices(Pattern *p) {
33713371
}
33723372

33733373
Type SubscriptDecl::getIndicesType() const {
3374-
return getType()->castTo<AnyFunctionType>()->getInput();
3374+
const auto type = getType();
3375+
if (type->is<ErrorType>())
3376+
return type;
3377+
return type->castTo<AnyFunctionType>()->getInput();
33753378
}
33763379

33773380
Type SubscriptDecl::getIndicesInterfaceType() const {

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,6 +2987,9 @@ bool TypeChecker::isRepresentableInObjC(const SubscriptDecl *SD,
29872987
if (TupleTy->getNumElements() == 1 && !TupleTy->getElement(0).isVararg())
29882988
IndicesType = TupleTy->getElementType(0);
29892989
}
2990+
2991+
if (IndicesType->is<ErrorType>())
2992+
return false;
29902993

29912994
bool IndicesResult = isRepresentableInObjC(SD->getDeclContext(), IndicesType);
29922995
bool ElementResult = isRepresentableInObjC(SD->getDeclContext(),

validation-test/compiler_crashers/24670-isunknownobjecttype.swift renamed to validation-test/compiler_crashers_fixed/24670-isunknownobjecttype.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27787-swift-typechecker-overapproximateosversionsatlocation.swift renamed to validation-test/compiler_crashers_fixed/27787-swift-typechecker-overapproximateosversionsatlocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

0 commit comments

Comments
 (0)