File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -5185,7 +5185,23 @@ Type SubscriptDecl::getElementInterfaceType() const {
5185
5185
auto elementTy = getInterfaceType ();
5186
5186
if (elementTy->is <ErrorType>())
5187
5187
return elementTy;
5188
- return elementTy->castTo <AnyFunctionType>()->getResult ();
5188
+ auto fnTy = elementTy->castTo <AnyFunctionType>();
5189
+ auto resultTy = fnTy->getResult ();
5190
+
5191
+ // Make sure we don't return a dependent type if the context is not
5192
+ // actually generic. This can only happen with subscripts because we're
5193
+ // apparently somewhat eager to leave dependent types as dependent
5194
+ // because of generic subscripts.
5195
+ if (resultTy->hasTypeParameter ()) {
5196
+ auto genericFnTy = cast<GenericFunctionType>(fnTy);
5197
+ auto sig = genericFnTy->getGenericSignature ();
5198
+ if (sig->areAllParamsConcrete ()) {
5199
+ // It's a bit unfortunate to canonicalize here.
5200
+ return sig->getCanonicalTypeInContext (resultTy);
5201
+ }
5202
+ }
5203
+
5204
+ return resultTy;
5189
5205
}
5190
5206
5191
5207
void SubscriptDecl::computeType () {
Original file line number Diff line number Diff line change @@ -18,3 +18,16 @@ func testXRead<T>(x: X<T>) -> T {
18
18
return x [ ] !
19
19
}
20
20
// CHECK: $s18subscript_accessor1XVxSgycisTf4dn_n
21
+
22
+ // Don't crash dealing with T? in a non-generic context.
23
+ // rdar://44762116
24
+ struct WillBeConcretelyConstrained < T> { }
25
+ extension WillBeConcretelyConstrained where T == Int {
26
+ subscript( key: Int ) -> T ? {
27
+ get { return nil }
28
+ set { }
29
+ }
30
+ }
31
+
32
+ // CHECK-LABEL: sil hidden [transparent] @$s18subscript_accessor27WillBeConcretelyConstrainedVAASiRszlEySiSgSiciM
33
+ // CHECK-SAME: $@yield_once @convention(method) (Int, @inout WillBeConcretelyConstrained<Int>) -> @yields @inout Optional<Int>
You can’t perform that action at this time.
0 commit comments