Skip to content

Commit 7c19460

Browse files
[test] Adding SR-12745 test cases
1 parent 02c454c commit 7c19460

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ ERROR(could_not_find_value_subscript,none,
5757
"value of type %0 has no subscripts",
5858
(Type))
5959

60-
ERROR(could_not_find_value_subscript_key_path,none,
61-
"value of type %0 has no matching subscript candidates; "
62-
"did you mean to use a key path subscript?",
63-
(Type))
64-
6560
ERROR(could_not_find_tuple_member,none,
6661
"value of tuple type %0 has no member %1", (Type, DeclNameRef))
6762

@@ -78,8 +73,8 @@ ERROR(could_not_find_value_dynamic_member,none,
7873
(Type, Type, DeclNameRef))
7974
ERROR(cannot_infer_contextual_keypath_type_specify_root,none,
8075
"cannot infer key path type from context; consider explicitly adding a root type", ())
81-
ERROR(cannot_infer_contextual_keypath_type_any_contextual,none,
82-
"'AnyKeyPath' does not provide enough context for root type to be inferred implicitly; "
76+
ERROR(cannot_infer_keypath_root_anykeypath_context,none,
77+
"'AnyKeyPath' does not provide enough context for root type to be inferred; "
8378
"consider explicitly adding a root type", ())
8479

8580
ERROR(could_not_find_type_member,none,

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6282,7 +6282,7 @@ bool UnableToInferKeyPathRootFailure::diagnoseAsError() {
62826282
if (contextualType &&
62836283
contextualType->getAnyNominal() == ctx.getAnyKeyPathDecl()) {
62846284
return emitDiagnostic(
6285-
diag::cannot_infer_contextual_keypath_type_any_contextual);
6285+
diag::cannot_infer_keypath_root_anykeypath_context);
62866286
}
62876287
return emitDiagnostic(
62886288
diag::cannot_infer_contextual_keypath_type_specify_root);

lib/Sema/CSFix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ enum class FixKind : uint8_t {
261261
/// Allow key path to be bound to a function type with more than 1 argument
262262
AllowMultiArgFuncKeyPathMismatch,
263263

264-
/// Specify key path root type when it cannot be infered by context.
264+
/// Specify key path root type when it cannot be infered from context.
265265
SpecifyKeyPathRootType,
266266

267267
};

test/expr/unary/keypath/keypath.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ func testKeyPath(sub: Sub, optSub: OptSub,
195195

196196
let _: AnyKeyPath = \A.property
197197
let _: AnyKeyPath = \C<A>.value
198-
let _: AnyKeyPath = \.property // expected-error{{ambiguous}}
198+
let _: AnyKeyPath = \.property // expected-error {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly adding a root type}} {{24-24=<#Root#>}}
199199
let _: AnyKeyPath = \C.value // expected-error{{generic parameter 'T' could not be inferred}}
200-
let _: AnyKeyPath = \.value // expected-error{{ambiguous}}
200+
let _: AnyKeyPath = \.value // expected-error {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly adding a root type}} {{24-24=<#Root#>}}
201201

202202
let _ = \Prop.[nonHashableSub] // expected-error{{subscript index of type 'NonHashableSub' in a key path must be Hashable}}
203203
let _ = \Prop.[sub, sub]
@@ -893,6 +893,15 @@ struct SR_12290 {
893893
}
894894
}
895895

896+
func testKeyPathHole() {
897+
_ = \.x // expected-error {{cannot infer key path type from context; consider explicitly adding a root type}} {{8-8=<#Root#>}}
898+
let _ : AnyKeyPath = \.x
899+
// expected-error@-1 {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly adding a root type}} {{25-25=<#Root#>}}
900+
901+
func f(_ i: Int) {}
902+
f(\.x) // expected-error {{cannot infer key path type from context; consider explicitly adding a root type}} {{6-6=<#Root#>}}
903+
}
904+
896905
func testSyntaxErrors() { // expected-note{{}}
897906
_ = \. ; // expected-error{{expected member name following '.'}}
898907
_ = \.a ;

0 commit comments

Comments
 (0)