Skip to content

Commit ccc70b7

Browse files
authored
Merge pull request #26097 from jckarter/opaque-type-redeclaration-collision
Don't allow overloading by opaque types with different constraints.
2 parents a7464e9 + a92fd9d commit ccc70b7

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
@@ -2410,7 +2410,7 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
24102410
// Functions and subscripts cannot overload differing only in opaque return
24112411
// types. Replace the opaque type with `Any`.
24122412
if (auto opaque = type->getAs<OpaqueTypeArchetypeType>()) {
2413-
type = opaque->getExistentialType();
2413+
type = ProtocolCompositionType::get(ctx, {}, /*hasAnyObject*/ false);
24142414
}
24152415

24162416
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)