Skip to content

Commit ecdc993

Browse files
committed
[Type checker] Tolerate invalid expressions in the error-handling checker.
When errors occur in the processing of expressions, we can end up with invalid ASTs where the application of an operator declared within a type is missing its "self" argument. Tolerate such ASTs in the error-handling checker.
1 parent 5349486 commit ecdc993

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Sema/TypeCheckError.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,20 @@ class ApplyClassifier {
428428
// count, then this is a call to the opaque value returned from
429429
// the function.
430430
if (args.size() != fnRef.getNumArgumentsForFullApply()) {
431+
// Special case: a reference to an operator within a type might be
432+
// missing 'self'.
433+
// FIXME: The issue here is that this is an ill-formed expression, but
434+
// we don't know it from the structure of the expression.
435+
if (args.size() == 1 && fnRef.getKind() == AbstractFunction::Function &&
436+
isa<FuncDecl>(fnRef.getFunction()) &&
437+
cast<FuncDecl>(fnRef.getFunction())->isOperator() &&
438+
fnRef.getNumArgumentsForFullApply() == 2 &&
439+
fnRef.getFunction()->getDeclContext()->isTypeContext()) {
440+
// Can only happen with invalid code.
441+
assert(fnRef.getFunction()->getASTContext().Diags.hadAnyError());
442+
return Classification::forInvalidCode();
443+
}
444+
431445
assert(args.size() > fnRef.getNumArgumentsForFullApply() &&
432446
"partial application was throwing?");
433447
return Classification::forThrow(PotentialReason::forThrowingApply());
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
// REQUIRES: asserts
1010
func a{guard let[]=(a||()A

0 commit comments

Comments
 (0)