AST: Resolve inherited types in usesFeatureRethrowsProtocol().

Previously, `usesFeatureRethrowsProtocol()` could mistakenly return false in
lazy typechecking mode since the types in an inheritance clause might not have
been resolved yet.
This commit is contained in:
Allan Shortlidge
2023-09-06 15:01:29 -07:00
parent e24f447eab
commit fd3714e086
4 changed files with 27 additions and 4 deletions

View File

@@ -2955,8 +2955,8 @@ static bool usesFeatureRethrowsProtocol(
// Check an inheritance clause for a marker protocol.
auto checkInherited = [&](InheritedTypes inherited) -> bool {
for (const auto &inheritedEntry : inherited.getEntries()) {
if (auto inheritedType = inheritedEntry.getType()) {
for (unsigned i : inherited.getIndices()) {
if (auto inheritedType = inherited.getResolvedType(i)) {
if (inheritedType->isExistentialType()) {
auto layout = inheritedType->getExistentialLayout();
for (ProtocolDecl *proto : layout.getProtocols()) {

View File

@@ -53,6 +53,10 @@ public protocol PublicProto {
func req() -> Int // expected-note 2 {{protocol requires function 'req()' with type '() -> Int'; add a stub for conformance}}
}
@rethrows public protocol PublicRethrowsProto {
func req() throws -> Int
}
protocol InternalProto {
func goodReq() -> Int // expected-note 2 {{protocol requires function 'goodReq()' with type '() -> Int'; add a stub for conformance}}
func badReq() -> DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
@@ -139,6 +143,12 @@ extension String: PublicProto {
extension String: InternalProto {} // expected-error {{type 'String' does not conform to protocol 'InternalProto'}}
extension Int: PublicRethrowsProto {
public func req() throws -> Int {
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
}
}
struct InternalStructConformingToPublicProto: PublicProto { // expected-error {{type 'InternalStructConformingToPublicProto' does not conform to protocol 'PublicProto'}}
}

View File

@@ -29,6 +29,11 @@
// CHECK: public protocol PublicProto {
// CHECK: func req() -> Swift.Int
// CHECK: }
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK: @rethrows public protocol PublicRethrowsProto {
// CHECK: func req() throws -> Swift.Int
// CHECK: }
// CHECK: #endif
// CHECK: public struct PublicStruct {
// CHECK: public init(x: Swift.Int)
// CHECK: public func publicMethod() -> Swift.Int
@@ -52,3 +57,8 @@
// CHECK: extension Swift.String : lazy_typecheck.PublicProto {
// CHECK: public func req() -> Swift.Int
// CHECK: }
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK: extension Swift.Int : lazy_typecheck.PublicRethrowsProto {
// CHECK: public func req() throws -> Swift.Int
// CHECK: }
// CHECK: #endif

View File

@@ -55,10 +55,13 @@ exports:
'_$s14lazy_typecheck12PublicStructV18publicStaticMethodyyFZ',
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructVMa',
'_$s14lazy_typecheck12PublicStructVMn', '_$s14lazy_typecheck12PublicStructVN',
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck19PublicRethrowsProtoMp',
'_$s14lazy_typecheck19PublicRethrowsProtoP3reqSiyKFTj', '_$s14lazy_typecheck19PublicRethrowsProtoP3reqSiyKFTq',
'_$s14lazy_typecheck19PublicRethrowsProtoTL', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryF',
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryFQOMQ',
'_$s14lazy_typecheck32constrainedGenericPublicFunctionyyxAA0E5ProtoRzlF',
'_$sSS14lazy_typecheck11PublicProtoAAMc', '_$sSS14lazy_typecheck11PublicProtoAAWP',
'_$sSS14lazy_typecheckE3reqSiyF' ]
'_$sSS14lazy_typecheckE3reqSiyF', '_$sSi14lazy_typecheck19PublicRethrowsProtoAAMc',
'_$sSi14lazy_typecheck19PublicRethrowsProtoAAWP', '_$sSi14lazy_typecheckE3reqSiyKF' ]
...