Skip to content

Commit 857987f

Browse files
authored
Merge pull request #68251 from tshortli/emit-module-lazy-typecheck-classes
NFC: Expand -experimental-lazy-typecheck test coverage
2 parents fca9db2 + 1b08ab5 commit 857987f

File tree

5 files changed

+106
-33
lines changed

5 files changed

+106
-33
lines changed

test/Inputs/lazy_typecheck.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func internalFunc() -> DoesNotExist { // expected-error {{cannot find type 'Does
2222
}
2323

2424
@inlinable func inlinableFunc() -> Int {
25-
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
25+
return 1
2626
}
2727

2828
private func privateFunc() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
@@ -61,13 +61,25 @@ protocol InternalProto {
6161
public struct PublicStruct {
6262
// FIXME: Test properties
6363

64+
public init(x: Int) {
65+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
66+
}
67+
6468
public func publicMethod() -> Int {
6569
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
6670
}
6771

72+
public static func publicStaticMethod() {
73+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
74+
}
75+
6876
func internalMethod() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
6977
return 1
7078
}
79+
80+
static func internalStaticMethod() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
81+
return 1
82+
}
7183
}
7284

7385
struct InternalStruct: DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
@@ -76,6 +88,32 @@ struct InternalStruct: DoesNotExist { // expected-error {{cannot find type 'Does
7688
func f(_ x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}}
7789
}
7890

91+
public class PublicClass {
92+
// FIXME: Test properties
93+
94+
public init(x: Int) {
95+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
96+
}
97+
98+
// FIXME: TBDGen causes this constructor to be type checked
99+
// init(_ x: DoesNotExist) {}
100+
101+
public func publicMethod() -> Int {
102+
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
103+
}
104+
105+
public class func publicClassMethod() {
106+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
107+
}
108+
109+
// FIXME: TBDGen causes these methods to be type checked
110+
// func internalMethod() -> DoesNotExist {}
111+
// class func internalClassMethod() -> DoesNotExist {}
112+
}
113+
114+
class InternalClass: DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
115+
init(x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}}
116+
}
79117
// FIXME: Test enums
80118
// FIXME: Test conformances
81119
// FIXME: Test global vars
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This source file contains an example client of all the public declarations
2+
// exposed by the library implemented in lazy_typecheck.swift.
3+
4+
import lazy_typecheck
5+
6+
struct ConformsToPublicProto: PublicProto {
7+
func req() -> Int { return 1 }
8+
}
9+
10+
func testGlobalFunctions() {
11+
_ = publicFunc()
12+
_ = publicFuncWithDefaultArg()
13+
#if TEST_PACKAGE
14+
_ = packageFunc()
15+
#endif
16+
constrainedGenericPublicFunction(ConformsToPublicProto())
17+
if #available(SwiftStdlib 5.1, *) {
18+
_ = publicFuncWithOpaqueReturnType()
19+
_ = publicAEICFuncWithOpaqueReturnType()
20+
}
21+
}
22+
23+
func testPublicStruct() {
24+
var s = PublicStruct(x: 1)
25+
_ = s.publicMethod()
26+
PublicStruct.publicStaticMethod()
27+
}
28+
29+
func testPublicClass() {
30+
let c = PublicClass(x: 2)
31+
_ = c.publicMethod()
32+
PublicClass.publicClassMethod()
33+
}

test/ModuleInterface/lazy-typecheck.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -emit-module -emit-module-path /dev/null -emit-module-interface-path %t/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-serialize-external-decls-only
3+
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-serialize-external-decls-only
44
// RUN: %FileCheck %s < %t/lazy_typecheck.swiftinterface
55

6+
// RUN: rm -rf %t/*.swiftmodule
7+
// RUN: %target-swift-frontend -package-name Package -typecheck %S/../Inputs/lazy_typecheck_client.swift -I %t
8+
69
// CHECK: import Swift
710

811
// CHECK: public func publicFunc() -> Swift.Int
912
// CHECK: publicFuncWithDefaultArg(_ x: Swift.Int = 1) -> Swift.Int
1013
// CHECK: @inlinable internal func inlinableFunc() -> Swift.Int {
11-
// CHECK-NEXT: return true // expected-error {{[{][{]}}cannot convert return expression of type 'Bool' to return type 'Int'{{[}][}]}}
14+
// CHECK-NEXT: return 1
1215
// CHECK-NEXT: }
1316
// CHECK: public func constrainedGenericPublicFunction<T>(_ t: T) where T : lazy_typecheck.PublicProto
1417
// CHECK: @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@@ -28,5 +31,14 @@
2831
// CHECK: }
2932

3033
// CHECK: public struct PublicStruct {
34+
// CHECK: public init(x: Swift.Int)
35+
// CHECK: public func publicMethod() -> Swift.Int
36+
// CHECK: public static func publicStaticMethod()
37+
// CHECK: }
38+
39+
// CHECK: public class PublicClass {
40+
// CHECK: public init(x: Swift.Int)
3141
// CHECK: public func publicMethod() -> Swift.Int
42+
// CHECK: public class func publicClassMethod()
43+
// CHECK: deinit
3244
// CHECK: }
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -enable-library-evolution -parse-as-library -package-name Package -typecheck -verify
33
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -emit-module -emit-module-path %t/lazy_typecheck.swiftmodule -enable-library-evolution -parse-as-library -package-name Package -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-serialize-external-decls-only
4-
// RUN: %target-swift-frontend -package-name Package -typecheck %s -I %t
54

6-
import lazy_typecheck
7-
8-
struct ConformsToPublicProto: PublicProto {
9-
func req() -> Int { return 1 }
10-
}
11-
12-
func testGlobalFunctions() {
13-
_ = publicFunc()
14-
_ = publicFuncWithDefaultArg()
15-
_ = packageFunc()
16-
constrainedGenericPublicFunction(ConformsToPublicProto())
17-
if #available(SwiftStdlib 5.1, *) {
18-
_ = publicFuncWithOpaqueReturnType()
19-
_ = publicAEICFuncWithOpaqueReturnType()
20-
}
21-
}
22-
23-
func testPublicStruct(_ s: PublicStruct) {
24-
_ = s.publicMethod()
25-
}
5+
// RUN: %target-swift-frontend -package-name Package -typecheck %S/../Inputs/lazy_typecheck_client.swift -D TEST_PACKAGE -I %t

test/TBD/lazy-typecheck.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ compatibility-version: 0
1717
swift-abi-version: 7
1818
exports:
1919
- targets: [ arm64-macos ]
20-
symbols: [ '_$s14lazy_typecheck10publicFuncSiyF', '_$s14lazy_typecheck11PublicProtoMp',
21-
'_$s14lazy_typecheck11PublicProtoP3reqSiyFTj', '_$s14lazy_typecheck11PublicProtoP3reqSiyFTq',
22-
'_$s14lazy_typecheck11PublicProtoTL', '_$s14lazy_typecheck11packageFuncSiyF',
23-
'_$s14lazy_typecheck12PublicStructV12publicMethodSiyF', '_$s14lazy_typecheck12PublicStructVMa',
24-
'_$s14lazy_typecheck12PublicStructVMn', '_$s14lazy_typecheck12PublicStructVN',
25-
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
26-
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryF',
27-
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryFQOMQ',
28-
'_$s14lazy_typecheck32constrainedGenericPublicFunctionyyxAA0E5ProtoRzlF' ]
20+
symbols: [ '_$s14lazy_typecheck10publicFuncSiyF', '_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTj',
21+
'_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTq',
22+
'_$s14lazy_typecheck11PublicClassC12publicMethodSiyFTj', '_$s14lazy_typecheck11PublicClassC12publicMethodSiyFTq',
23+
'_$s14lazy_typecheck11PublicClassC1xACSi_tcfC', '_$s14lazy_typecheck11PublicClassC1xACSi_tcfCTj',
24+
'_$s14lazy_typecheck11PublicClassC1xACSi_tcfCTq', '_$s14lazy_typecheck11PublicClassC1xACSi_tcfc',
25+
'_$s14lazy_typecheck11PublicClassCMa', '_$s14lazy_typecheck11PublicClassCMm',
26+
'_$s14lazy_typecheck11PublicClassCMn', '_$s14lazy_typecheck11PublicClassCMo',
27+
'_$s14lazy_typecheck11PublicClassCMu', '_$s14lazy_typecheck11PublicClassCN',
28+
'_$s14lazy_typecheck11PublicClassCfD', '_$s14lazy_typecheck11PublicClassCfd',
29+
'_$s14lazy_typecheck11PublicProtoMp', '_$s14lazy_typecheck11PublicProtoP3reqSiyFTj',
30+
'_$s14lazy_typecheck11PublicProtoP3reqSiyFTq', '_$s14lazy_typecheck11PublicProtoTL',
31+
'_$s14lazy_typecheck11packageFuncSiyF', '_$s14lazy_typecheck12PublicStructV12publicMethodSiyF',
32+
'_$s14lazy_typecheck12PublicStructV18publicStaticMethodyyFZ',
33+
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructVMa',
34+
'_$s14lazy_typecheck12PublicStructVMn', '_$s14lazy_typecheck12PublicStructVN',
35+
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck24publicFuncWithDefaultArgyS2iF',
36+
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryF',
37+
'_$s14lazy_typecheck30publicFuncWithOpaqueReturnTypeQryFQOMQ',
38+
'_$s14lazy_typecheck32constrainedGenericPublicFunctionyyxAA0E5ProtoRzlF' ]
2939
...

0 commit comments

Comments
 (0)