Skip to content

Commit 0b612a4

Browse files
committed
AST: Temporarily remove calls to TypeBase::getMinimalCanonicalType()
This is the transform that minimizes a protocol composition according to generic signature rules, so for example P & C where C already conforms to P will minimize down to just C. Unfortunately this calls ASTContext::getOpenedArchetypeSignature(), which is broken when the protocol composition involves a superclass constraint containing an interface type. For example, calling ASTContext::getOpenedArchetypeSignature() on P & C<T> will build a signature <Self where Self : P, Self : C<T>> The generic parameter 'T' occurs as a "free variable", which is invalid. What we ought to do is build a generic signature with the outer parameters and requirements of the DeclContext where the opened existential type appears, and then add 'Self' at the end of the parameter list. Until that is implemented, replace these calls with getCanonicalType() to avoid triggering Requirement Machine assertions.
1 parent 910c2a4 commit 0b612a4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
29142914
/*topLevelFunction=*/true, isMethod,
29152915
/*isInitializer=*/isa<ConstructorDecl>(afd),
29162916
getNumCurryLevels())
2917-
->getMinimalCanonicalType();
2917+
->getCanonicalType();
29182918
}
29192919

29202920
if (isa<AbstractStorageDecl>(this)) {
@@ -2930,22 +2930,22 @@ CanType ValueDecl::getOverloadSignatureType() const {
29302930
/*topLevelFunction=*/true,
29312931
/*isMethod=*/false,
29322932
/*isInitializer=*/false, getNumCurryLevels())
2933-
->getMinimalCanonicalType();
2933+
->getCanonicalType();
29342934
}
29352935

29362936
// We want to curry the default signature type with the 'self' type of the
29372937
// given context (if any) in order to ensure the overload signature type
29382938
// is unique across different contexts, such as between a protocol extension
29392939
// and struct decl.
29402940
return defaultSignatureType->addCurriedSelfType(getDeclContext())
2941-
->getMinimalCanonicalType();
2941+
->getCanonicalType();
29422942
}
29432943

29442944
if (isa<EnumElementDecl>(this)) {
29452945
auto mappedType = mapSignatureFunctionType(
29462946
getASTContext(), getInterfaceType(), /*topLevelFunction=*/false,
29472947
/*isMethod=*/false, /*isInitializer=*/false, getNumCurryLevels());
2948-
return mappedType->getMinimalCanonicalType();
2948+
return mappedType->getCanonicalType();
29492949
}
29502950

29512951
// Note: If you add more cases to this function, you should update the

test/type/subclass_composition.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,28 @@ struct Unrelated {}
4848
// If a class conforms to a protocol concretely, the resulting protocol
4949
// composition type should be equivalent to the class type.
5050
//
51-
// FIXME: Not implemented yet.
51+
// FIXME: Disabled for now.
5252
//
5353

54-
func alreadyConforms<T>(_: Base<T>) {} // expected-note 3 {{'alreadyConforms' previously declared here}}
55-
func alreadyConforms<T>(_: Base<T> & P1) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
54+
func alreadyConforms<T>(_: Base<T>) {} // expected-note {{'alreadyConforms' previously declared here}}
55+
func alreadyConforms<T>(_: Base<T> & P1) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConforms'}} expected-note {{'alreadyConforms' previously declared here}}
5656
func alreadyConforms<T>(_: Base<T> & AnyObject) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
5757
func alreadyConforms<T>(_: Base<T> & P1 & AnyObject) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
5858

59-
func alreadyConformsMeta<T>(_: Base<T>.Type) {} // expected-note 7 {{'alreadyConformsMeta' previously declared here}}
60-
func alreadyConformsMeta<T>(_: (Base<T> & P1).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
61-
func alreadyConformsMeta<T>(_: (Base<T> & P1).Protocol) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
59+
func alreadyConformsMeta<T>(_: Base<T>.Type) {} // expected-note {{'alreadyConformsMeta' previously declared here}}
60+
func alreadyConformsMeta<T>(_: (Base<T> & P1).Type) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConformsMeta'}} expected-note {{'alreadyConformsMeta' previously declared here}}
61+
func alreadyConformsMeta<T>(_: (Base<T> & P1).Protocol) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConformsMeta'}} expected-note 3 {{'alreadyConformsMeta' previously declared here}}
6262
func alreadyConformsMeta<T>(_: (any Base<T> & P1).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6363
func alreadyConformsMeta<T>(_: (Base<T> & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6464
func alreadyConformsMeta<T>(_: (Base<T> & P1 & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6565
func alreadyConformsMeta<T>(_: (Base<T> & P1 & AnyObject).Protocol) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6666
func alreadyConformsMeta<T>(_: (any Base<T> & P1 & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
6767

68-
func alreadyConforms(_: P3) {} // expected-note {{'alreadyConforms' previously declared here}}
69-
func alreadyConforms(_: P3 & AnyObject) {} // expected-error {{invalid redeclaration of 'alreadyConforms'}}
68+
func alreadyConforms(_: P3) {} // e/xpected-note {{'alreadyConforms' previously declared here}}
69+
func alreadyConforms(_: P3 & AnyObject) {} // FIXME e/xpected-error {{invalid redeclaration of 'alreadyConforms'}}
7070

71-
func alreadyConformsMeta(_: P3.Type) {} // expected-note {{'alreadyConformsMeta' previously declared here}}
72-
func alreadyConformsMeta(_: (P3 & AnyObject).Type) {} // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
71+
func alreadyConformsMeta(_: P3.Type) {} // FIXME e/xpected-note {{'alreadyConformsMeta' previously declared here}}
72+
func alreadyConformsMeta(_: (P3 & AnyObject).Type) {} // FIXME ex/pected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
7373

7474
// SE-0156 stipulates that a composition can contain multiple classes, as long
7575
// as they are all the same.

0 commit comments

Comments
 (0)