Skip to content

Commit 3c025ff

Browse files
authored
Merge pull request #25463 from xedin/rdar-48937223-5.1-06-12
[5.1 06/12][CSApply] Don't try to transform editor placeholder if it's type is invalid
2 parents 31fd3cf + d970786 commit 3c025ff

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4041,6 +4041,19 @@ namespace {
40414041
simplifyExprType(E);
40424042
auto valueType = cs.getType(E);
40434043

4044+
// TODO(diagnostics): Once all of the diagnostics are moved to
4045+
// new diagnostics framework this check could be eliminated.
4046+
//
4047+
// Only way for this to happen is CSDiag try to re-typecheck
4048+
// sub-expression which contains this placeholder with
4049+
// `AllowUnresolvedTypeVariables` flag set.
4050+
//
4051+
// A better solution could be to replace placeholders with this
4052+
// implicit call early on and type-check that call together with
4053+
// the rest of the constraint system.
4054+
if (valueType->hasUnresolvedType())
4055+
return nullptr;
4056+
40444057
auto &tc = cs.getTypeChecker();
40454058
auto &ctx = tc.Context;
40464059
// Synthesize a call to _undefined() of appropriate type.
@@ -7597,7 +7610,11 @@ namespace {
75977610
ClosuresToTypeCheck.push_back(closure);
75987611
}
75997612

7600-
tc.ClosuresWithUncomputedCaptures.push_back(closure);
7613+
// Don't try to register captures if constraint system is used to
7614+
// produce diagnostics for one of the sub-expressions.
7615+
if (!cs.Options.contains(
7616+
ConstraintSystemFlags::SubExpressionDiagnostics))
7617+
tc.ClosuresWithUncomputedCaptures.push_back(closure);
76017618

76027619
return { false, closure };
76037620
}

lib/Sema/ConstraintSystem.h

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

843851
/// 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
@@ -2190,6 +2190,9 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
21902190
if (options.contains(TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType))
21912191
csOptions |= ConstraintSystemFlags::UnderlyingTypeForOpaqueReturnType;
21922192

2193+
if (options.contains(TypeCheckExprFlags::SubExpressionDiagnostics))
2194+
csOptions |= ConstraintSystemFlags::SubExpressionDiagnostics;
2195+
21932196
ConstraintSystem cs(*this, dc, csOptions, expr);
21942197
cs.baseCS = baseCS;
21952198

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {}
4+
5+
func fn<T, U: P>(_ arg1: T, arg2: (T) -> U) {}
6+
7+
func test(str: String) {
8+
fn(str) { arg in
9+
<#FOO#> // expected-error {{editor placeholder in source file}}
10+
}
11+
}

0 commit comments

Comments
 (0)