Skip to content

Commit 9a993b6

Browse files
committed
Tests: Refactor client of the lazy_typecheck module into a shared input.
This allows the ModuleInterface test to attempt to build a client against the emitted `.swiftinterface` which will help us ensure the emitted interface is correct.
1 parent 5422f9a commit 9a993b6

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

test/Inputs/lazy_typecheck.swift

Lines changed: 1 addition & 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}}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(_ s: PublicStruct) {
24+
_ = s.publicMethod()
25+
}

test/ModuleInterface/lazy-typecheck.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
// 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
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, *)
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

0 commit comments

Comments
 (0)