Skip to content

Commit fd3714e

Browse files
committed
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.
1 parent e24f447 commit fd3714e

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,8 +2955,8 @@ static bool usesFeatureRethrowsProtocol(
29552955

29562956
// Check an inheritance clause for a marker protocol.
29572957
auto checkInherited = [&](InheritedTypes inherited) -> bool {
2958-
for (const auto &inheritedEntry : inherited.getEntries()) {
2959-
if (auto inheritedType = inheritedEntry.getType()) {
2958+
for (unsigned i : inherited.getIndices()) {
2959+
if (auto inheritedType = inherited.getResolvedType(i)) {
29602960
if (inheritedType->isExistentialType()) {
29612961
auto layout = inheritedType->getExistentialLayout();
29622962
for (ProtocolDecl *proto : layout.getProtocols()) {

test/Inputs/lazy_typecheck.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public protocol PublicProto {
5353
func req() -> Int // expected-note 2 {{protocol requires function 'req()' with type '() -> Int'; add a stub for conformance}}
5454
}
5555

56+
@rethrows public protocol PublicRethrowsProto {
57+
func req() throws -> Int
58+
}
59+
5660
protocol InternalProto {
5761
func goodReq() -> Int // expected-note 2 {{protocol requires function 'goodReq()' with type '() -> Int'; add a stub for conformance}}
5862
func badReq() -> DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
@@ -139,6 +143,12 @@ extension String: PublicProto {
139143

140144
extension String: InternalProto {} // expected-error {{type 'String' does not conform to protocol 'InternalProto'}}
141145

146+
extension Int: PublicRethrowsProto {
147+
public func req() throws -> Int {
148+
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
149+
}
150+
}
151+
142152
struct InternalStructConformingToPublicProto: PublicProto { // expected-error {{type 'InternalStructConformingToPublicProto' does not conform to protocol 'PublicProto'}}
143153
}
144154

test/ModuleInterface/lazy-typecheck.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
// CHECK: public protocol PublicProto {
3030
// CHECK: func req() -> Swift.Int
3131
// CHECK: }
32+
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
33+
// CHECK: @rethrows public protocol PublicRethrowsProto {
34+
// CHECK: func req() throws -> Swift.Int
35+
// CHECK: }
36+
// CHECK: #endif
3237
// CHECK: public struct PublicStruct {
3338
// CHECK: public init(x: Swift.Int)
3439
// CHECK: public func publicMethod() -> Swift.Int
@@ -52,3 +57,8 @@
5257
// CHECK: extension Swift.String : lazy_typecheck.PublicProto {
5358
// CHECK: public func req() -> Swift.Int
5459
// CHECK: }
60+
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
61+
// CHECK: extension Swift.Int : lazy_typecheck.PublicRethrowsProto {
62+
// CHECK: public func req() throws -> Swift.Int
63+
// CHECK: }
64+
// CHECK: #endif

test/TBD/lazy-typecheck.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ exports:
5555
'_$s14lazy_typecheck12PublicStructV18publicStaticMethodyyFZ',
5656
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructVMa',
5757
'_$s14lazy_typecheck12PublicStructVMn', '_$s14lazy_typecheck12PublicStructVN',
58-
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
58+
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck19PublicRethrowsProtoMp',
59+
'_$s14lazy_typecheck19PublicRethrowsProtoP3reqSiyKFTj', '_$s14lazy_typecheck19PublicRethrowsProtoP3reqSiyKFTq',
60+
'_$s14lazy_typecheck19PublicRethrowsProtoTL', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
5961
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryF',
6062
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryFQOMQ',
6163
'_$s14lazy_typecheck32constrainedGenericPublicFunctionyyxAA0E5ProtoRzlF',
6264
'_$sSS14lazy_typecheck11PublicProtoAAMc', '_$sSS14lazy_typecheck11PublicProtoAAWP',
63-
'_$sSS14lazy_typecheckE3reqSiyF' ]
65+
'_$sSS14lazy_typecheckE3reqSiyF', '_$sSi14lazy_typecheck19PublicRethrowsProtoAAMc',
66+
'_$sSi14lazy_typecheck19PublicRethrowsProtoAAWP', '_$sSi14lazy_typecheckE3reqSiyKF' ]
6467
...

0 commit comments

Comments
 (0)