Skip to content

Commit 26d0324

Browse files
committed
[CSApply] Don't try to transform editor placeholder if it's type is invalid
CSDiag could re-typecheck closure or other expression which has editor placeholder inside allowing type variables be bound to unresolved type, which doesn't really form a valid solution to be applied to AST. So we need to guard against trying to transform placeholder into a call to `_undefined` in such case, otherwise in asserts build it's going to crash with an assert but in release build it would crash in some other place e.g. xSILGen or trying to type-check captures. Resolves: rdar://problem/48937223 Resolves: rdar://problem/51599529
1 parent 59bc60e commit 26d0324

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 13 additions & 0 deletions
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.
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)