Skip to content

Commit 59bc60e

Browse files
committed
[ConstraintSystem] Don't track captures if solver was in diagnostic mode
If solution application is attempted for one of the sub-expressions, while diagnostics are trying to narrow down where the failure is located, don't record that captures need to be computed for closures, because that could fail later on as in such conditions expressions are not guaranteed to have correct types (e.g. some types could be set to "unresolved").
1 parent 735a884 commit 59bc60e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7398,7 +7398,11 @@ namespace {
73987398
ClosuresToTypeCheck.push_back(closure);
73997399
}
74007400

7401-
tc.ClosuresWithUncomputedCaptures.push_back(closure);
7401+
// Don't try to register captures if constraint system is used to
7402+
// produce diagnostics for one of the sub-expressions.
7403+
if (!cs.Options.contains(
7404+
ConstraintSystemFlags::SubExpressionDiagnostics))
7405+
tc.ClosuresWithUncomputedCaptures.push_back(closure);
74027406

74037407
return { false, closure };
74047408
}

lib/Sema/ConstraintSystem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,14 @@ enum class ConstraintSystemFlags {
840840
/// If set, the top-level expression may be able to provide an underlying
841841
/// type for the contextual opaque archetype.
842842
UnderlyingTypeForOpaqueReturnType = 0x40,
843+
844+
/// FIXME(diagnostics): Once diagnostics are completely switched to new
845+
/// framework, this flag could be removed as obsolete.
846+
///
847+
/// If set, this identifies constraint system as being used to re-typecheck
848+
/// one of the sub-expressions as part of the expression diagnostics, which
849+
/// is attempting to narrow down failure location.
850+
SubExpressionDiagnostics = 0x80,
843851
};
844852

845853
/// Options that affect the constraint system as a whole.

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,9 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
21842184
if (options.contains(TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType))
21852185
csOptions |= ConstraintSystemFlags::UnderlyingTypeForOpaqueReturnType;
21862186

2187+
if (options.contains(TypeCheckExprFlags::SubExpressionDiagnostics))
2188+
csOptions |= ConstraintSystemFlags::SubExpressionDiagnostics;
2189+
21872190
ConstraintSystem cs(*this, dc, csOptions, expr);
21882191
cs.baseCS = baseCS;
21892192

0 commit comments

Comments
 (0)