Skip to content

Commit 593f1de

Browse files
committed
Test that macros can be applied to imported Objective-C declarations
These currently end up as "open", which is incorrect (we need to make them "final"). This cannot be addressed until we pass the lexical context down to the macro, which is currently... a bit tricky.
1 parent ead028b commit 593f1de

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

test/Inputs/clang-importer-sdk/usr/include/completion_handler_globals.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ typedef struct SlowComputer {
77
void computer_divide(const SlowComputer *computer, double x, double y, void (* _Nonnull completionHandler)(double x))
88
__attribute__((swift_attr("@macro_library.AddAsync")))
99
__attribute__((swift_name("SlowComputer.divide(self:_:_:completionHandler:)")));
10+
11+
12+
#if __OBJC__
13+
@import Foundation;
14+
15+
@interface Computer: NSObject
16+
-(void)multiply:(double)x by:(double)y afterDone:(void (^ _Nonnull)(double x))afterDone
17+
__attribute__((swift_attr("@macro_library.AddAsync")))
18+
__attribute__((swift_async(none)));
19+
@end
20+
#endif

test/Macros/expand_on_imported.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: swift_swift_parser, executable_test
1+
// REQUIRES: swift_swift_parser, executable_test, concurrency
22

33
// RUN: %empty-directory(%t)
44
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: swift_swift_parser, executable_test, objc_interop, concurrency
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5
5+
6+
// Build the macro library to give us access to AddAsync.
7+
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
8+
9+
// Diagnostics testing
10+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -swift-version 5 -enable-experimental-feature CodeItemMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name ModuleUser %s -I %t
11+
12+
import CompletionHandlerGlobals
13+
import macro_library
14+
15+
@available(SwiftStdlib 5.1, *)
16+
func testAll(x: Double, y: Double, computer: Computer, untypedComputer: AnyObject) async {
17+
let _: Double = await computer.multiply(x, by: y)
18+
19+
// expected-error@+1{{missing argument for parameter 'afterDone' in call}}
20+
untypedComputer.multiply(x, by: y)
21+
}

test/Macros/print_clang_expand_on_imported.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: swift_swift_parser, executable_test
1+
// REQUIRES: swift_swift_parser, executable_test, concurrency
22

33
// RUN: %empty-directory(%t)
44
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5
@@ -17,4 +17,3 @@ import CompletionHandlerGlobals
1717
// CHECK: public func divide(_ x: Double, _ y: Double) async -> Double
1818

1919
// CHECK: func async_divide(_ x: Double, _ y: Double) async -> Double
20-
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: swift_swift_parser, executable_test, objc_interop, concurrency
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5
5+
6+
// Build the macro library to give us access to AddAsync.
7+
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
8+
9+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -print-implicit-attrs -source-filename %s -module-to-print=CompletionHandlerGlobals -I %t -function-definitions=false -load-plugin-library %t/%target-library-name(MacroDefinition) -import-module macro_library > %t/imported.printed.txt
10+
// RUN: %FileCheck -input-file %t/imported.printed.txt %s
11+
12+
import CompletionHandlerGlobals
13+
14+
// CHECK: class Computer
15+
// FIXME: The "open" is odd here. We want this to be "final", but can't yet.
16+
// CHECK: open func multiply(_ x: Double, by y: Double) async -> Double

0 commit comments

Comments
 (0)