Skip to content

Commit a92fd9d

Browse files
committed
Don't allow overloading by opaque types with different constraints.
The mangling unfortunately doesn't take the constraints into account, leading to SR-10725 | rdar://problem/50987172. Changing the mangling at this point is hazardous, so it's probably best to disallow this for now.
1 parent ba73936 commit a92fd9d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
23692369
// Functions and subscripts cannot overload differing only in opaque return
23702370
// types. Replace the opaque type with `Any`.
23712371
if (auto opaque = type->getAs<OpaqueTypeArchetypeType>()) {
2372-
type = opaque->getExistentialType();
2372+
type = ProtocolCompositionType::get(ctx, {}, /*hasAnyObject*/ false);
23732373
}
23742374

23752375
return mapSignatureParamType(ctx, type);

test/type/opaque.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,30 +272,31 @@ func associatedTypeIdentity() {
272272
sameType(gary(doug()).r_out(), gary(candace()).r_out()) // expected-error{{}}
273273
}
274274

275-
func redeclaration() -> some P { return 0 } // expected-note{{previously declared}}
275+
func redeclaration() -> some P { return 0 } // expected-note 2{{previously declared}}
276276
func redeclaration() -> some P { return 0 } // expected-error{{redeclaration}}
277-
func redeclaration() -> some Q { return 0 }
277+
func redeclaration() -> some Q { return 0 } // expected-error{{redeclaration}}
278278
func redeclaration() -> P { return 0 }
279+
func redeclaration() -> Any { return 0 }
279280

280281
var redeclaredProp: some P { return 0 } // expected-note 3{{previously declared}}
281282
var redeclaredProp: some P { return 0 } // expected-error{{redeclaration}}
282283
var redeclaredProp: some Q { return 0 } // expected-error{{redeclaration}}
283284
var redeclaredProp: P { return 0 } // expected-error{{redeclaration}}
284285

285286
struct RedeclarationTest {
286-
func redeclaration() -> some P { return 0 } // expected-note{{previously declared}}
287+
func redeclaration() -> some P { return 0 } // expected-note 2{{previously declared}}
287288
func redeclaration() -> some P { return 0 } // expected-error{{redeclaration}}
288-
func redeclaration() -> some Q { return 0 }
289+
func redeclaration() -> some Q { return 0 } // expected-error{{redeclaration}}
289290
func redeclaration() -> P { return 0 }
290291

291292
var redeclaredProp: some P { return 0 } // expected-note 3{{previously declared}}
292293
var redeclaredProp: some P { return 0 } // expected-error{{redeclaration}}
293294
var redeclaredProp: some Q { return 0 } // expected-error{{redeclaration}}
294295
var redeclaredProp: P { return 0 } // expected-error{{redeclaration}}
295296

296-
subscript(redeclared _: Int) -> some P { return 0 } // expected-note{{previously declared}}
297+
subscript(redeclared _: Int) -> some P { return 0 } // expected-note 2{{previously declared}}
297298
subscript(redeclared _: Int) -> some P { return 0 } // expected-error{{redeclaration}}
298-
subscript(redeclared _: Int) -> some Q { return 0 }
299+
subscript(redeclared _: Int) -> some Q { return 0 } // expected-error{{redeclaration}}
299300
subscript(redeclared _: Int) -> P { return 0 }
300301
}
301302

0 commit comments

Comments
 (0)