mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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()) {
|
||||
|
||||
@@ -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'}}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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' ]
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user