File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1832,6 +1832,26 @@ SpecifyBaseTypeForOptionalUnresolvedMember::attempt(
1832
1832
if (memberDecl->isInstanceMember ())
1833
1833
continue ;
1834
1834
1835
+ // Disable this warning for ambiguities related to a
1836
+ // static member lookup in generic context because it's
1837
+ // possible to declare a member with the same name on
1838
+ // a concrete type and in an extension of a protocol
1839
+ // that type conforms to e.g.:
1840
+ //
1841
+ // struct S : P { static var test: S { ... }
1842
+ //
1843
+ // extension P where Self == S { static var test: { ... } }
1844
+ //
1845
+ // And use that in an optional context e.g. passing `.test`
1846
+ // to a parameter of expecting `S?`.
1847
+ if (auto *extension =
1848
+ dyn_cast<ExtensionDecl>(memberDecl->getDeclContext ())) {
1849
+ if (extension->getSelfProtocolDecl ()) {
1850
+ allOptionalBase = false ;
1851
+ break ;
1852
+ }
1853
+ }
1854
+
1835
1855
allOptionalBase &= bool (choice.getBaseType ()
1836
1856
->getMetatypeInstanceType ()
1837
1857
->getOptionalObjectType ());
Original file line number Diff line number Diff line change @@ -299,3 +299,20 @@ func test_fixit_with_where_clause() {
299
299
func test_assoc< T: TestWithAssoc > ( _: T ) { }
300
300
test_assoc ( . intVar) // expected-error {{contextual member reference to static property 'intVar' requires 'Self' constraint in the protocol extension}}
301
301
}
302
+
303
+ // rdar://77700261 - incorrect warning about assuming non-optional base for unresolved member lookup
304
+ struct WithShadowedMember : P { }
305
+
306
+ extension WithShadowedMember {
307
+ static var warnTest : WithShadowedMember { get { WithShadowedMember ( ) } }
308
+ }
309
+
310
+ extension P where Self == WithShadowedMember {
311
+ static var warnTest : WithShadowedMember { get { fatalError ( ) } }
312
+ }
313
+
314
+ func test_no_warning_about_optional_base( ) {
315
+ func test( _: WithShadowedMember ? ) { }
316
+
317
+ test ( . warnTest) // Ok and no warning even though the `warnTest` name is shadowed
318
+ }
You can’t perform that action at this time.
0 commit comments