Skip to content

Commit 0c98d57

Browse files
committed
---
yaml --- r: 348101 b: refs/heads/master c: d8dbed7 h: refs/heads/master i: 348099: 843b8e0
1 parent 4eb0f04 commit 0c98d57

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 49f7aa13c3f424145317f396337cfea313cf5c07
2+
refs/heads/master: d8dbed7eab1fb757faa42b7893aba21db8c94353
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/CSApply.cpp

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

3900+
// TODO(diagnostics): Once all of the diagnostics are moved to
3901+
// new diagnostics framework this check could be eliminated.
3902+
//
3903+
// Only way for this to happen is CSDiag try to re-typecheck
3904+
// sub-expression which contains this placeholder with
3905+
// `AllowUnresolvedTypeVariables` flag set.
3906+
//
3907+
// A better solution could be to replace placeholders with this
3908+
// implicit call early on and type-check that call together with
3909+
// the rest of the constraint system.
3910+
if (valueType->hasUnresolvedType())
3911+
return nullptr;
3912+
39003913
auto &tc = cs.getTypeChecker();
39013914
auto &ctx = tc.Context;
39023915
// Synthesize a call to _undefined() of appropriate type.
@@ -7398,7 +7411,11 @@ namespace {
73987411
ClosuresToTypeCheck.push_back(closure);
73997412
}
74007413

7401-
tc.ClosuresWithUncomputedCaptures.push_back(closure);
7414+
// Don't try to register captures if constraint system is used to
7415+
// produce diagnostics for one of the sub-expressions.
7416+
if (!cs.Options.contains(
7417+
ConstraintSystemFlags::SubExpressionDiagnostics))
7418+
tc.ClosuresWithUncomputedCaptures.push_back(closure);
74027419

74037420
return { false, closure };
74047421
}

trunk/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.

trunk/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

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)