Skip to content

Commit 2ad1589

Browse files
authored
Merge pull request #65434 from jreference/61440-no-generic-env-for-type-param
Sema: fix for 61440 (lib/AST/GenericEnvironment) no generic environme…
2 parents d90134c + e18b40b commit 2ad1589

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,9 +2556,9 @@ static bool fixItOverrideDeclarationTypesImpl(
25562556
});
25572557
}
25582558

2559-
auto resultType = subscript->getDeclContext()->mapTypeIntoContext(
2560-
subscript->getElementInterfaceType());
2561-
auto baseResultType = baseSubscript->getDeclContext()->mapTypeIntoContext(
2559+
auto resultType =
2560+
subscript->mapTypeIntoContext(subscript->getElementInterfaceType());
2561+
auto baseResultType = baseSubscript->mapTypeIntoContext(
25622562
baseSubscript->getElementInterfaceType());
25632563
fixedAny |= checkType(resultType, ParamDecl::Specifier::Default,
25642564
baseResultType, ParamDecl::Specifier::Default,

test/Sema/generic-subscript.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
4+
protocol P
5+
{
6+
subscript<Value>(x:Value) -> Int // expected-note {{protocol requires subscript with type '<Value> (Value) -> Int'; do you want to add a stub?}}
7+
{
8+
get
9+
}
10+
}
11+
12+
struct S:P // expected-error {{type 'S' does not conform to protocol 'P'}}
13+
{
14+
subscript<Value>(x:Int) -> Value // expected-note {{candidate has non-matching type '<Value> (Int) -> Value'}}
15+
{
16+
} // expected-error {{missing return in subscript expected to return 'Value'}}
17+
}
18+
19+
20+
21+
struct S2:P
22+
{
23+
subscript<Value>(x:Value) -> Int
24+
{
25+
return 123;
26+
}
27+
}
28+
29+
protocol P2
30+
{
31+
subscript(x:Int) -> Int
32+
{
33+
get
34+
}
35+
}
36+
37+
struct S3:P2
38+
{
39+
subscript(x:Int) -> Int
40+
{
41+
return x;
42+
}
43+
}
44+

0 commit comments

Comments
 (0)