Skip to content

Commit f326927

Browse files
committed
CSGen: Infer generic arguments in typed placeholders
1 parent 421bce3 commit f326927

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,9 +3273,10 @@ namespace {
32733273
Type visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) {
32743274
if (auto *placeholderRepr = E->getPlaceholderTypeRepr()) {
32753275
// Just resolve the referenced type.
3276-
// FIXME: The type reference needs to be opened into context.
32773276
return resolveTypeReferenceInExpression(
3278-
placeholderRepr, TypeResolverContext::InExpression, nullptr);
3277+
placeholderRepr, TypeResolverContext::InExpression,
3278+
// Introduce type variables for unbound generics.
3279+
OpenUnboundGenericType(CS, CS.getConstraintLocator(E)));
32793280
}
32803281

32813282
auto locator = CS.getConstraintLocator(E);

test/Sema/editor_placeholders.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
func foo(_ x: Int) -> Int {}
44
func foo(_ x: Float) -> Float {}
5+
func foo<T>(_ t: T) -> T {}
56

67
var v = foo(<#T##x: Float##Float#>) // expected-error {{editor placeholder}}
78
v = "" // expected-error {{cannot assign value of type 'String' to type 'Float'}}
@@ -36,3 +37,6 @@ func test_ambiguity_with_placeholders(pairs: [(rank: Int, count: Int)]) -> Bool
3637
// expected-error@-1 {{editor placeholder in source file}}
3738
// expected-error@-2 {{ambiguous use of 'subscript(_:)'}}
3839
}
40+
41+
let unboundInPlaceholder1: Array<Never> = <#T##Array#> // expected-error{{editor placeholder in source file}}
42+
let unboundInPlaceholder2: Array<Never> = foo(<#T##t: Array##Array<Never>#>) // expected-error{{editor placeholder in source file}}

0 commit comments

Comments
 (0)