mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
This commit is contained in:
@@ -7,3 +7,14 @@ typedef struct SlowComputer {
|
||||
void computer_divide(const SlowComputer *computer, double x, double y, void (* _Nonnull completionHandler)(double x))
|
||||
__attribute__((swift_attr("@macro_library.AddAsync")))
|
||||
__attribute__((swift_name("SlowComputer.divide(self:_:_:completionHandler:)")));
|
||||
|
||||
|
||||
#if __OBJC__
|
||||
@import Foundation;
|
||||
|
||||
@interface Computer: NSObject
|
||||
-(void)multiply:(double)x by:(double)y afterDone:(void (^ _Nonnull)(double x))afterDone
|
||||
__attribute__((swift_attr("@macro_library.AddAsync")))
|
||||
__attribute__((swift_async(none)));
|
||||
@end
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// REQUIRES: swift_swift_parser, executable_test
|
||||
// REQUIRES: swift_swift_parser, executable_test, concurrency
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// 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
|
||||
|
||||
21
test/Macros/expand_on_imported_objc.swift
Normal file
21
test/Macros/expand_on_imported_objc.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
// REQUIRES: swift_swift_parser, executable_test, objc_interop, concurrency
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// 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
|
||||
|
||||
// Build the macro library to give us access to AddAsync.
|
||||
// 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)
|
||||
|
||||
// Diagnostics testing
|
||||
// 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
|
||||
|
||||
import CompletionHandlerGlobals
|
||||
import macro_library
|
||||
|
||||
@available(SwiftStdlib 5.1, *)
|
||||
func testAll(x: Double, y: Double, computer: Computer, untypedComputer: AnyObject) async {
|
||||
let _: Double = await computer.multiply(x, by: y)
|
||||
|
||||
// expected-error@+1{{missing argument for parameter 'afterDone' in call}}
|
||||
untypedComputer.multiply(x, by: y)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// REQUIRES: swift_swift_parser, executable_test
|
||||
// REQUIRES: swift_swift_parser, executable_test, concurrency
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// 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
|
||||
// CHECK: public func divide(_ x: Double, _ y: Double) async -> Double
|
||||
|
||||
// CHECK: func async_divide(_ x: Double, _ y: Double) async -> Double
|
||||
|
||||
|
||||
16
test/Macros/print_clang_expand_on_imported_objc.swift
Normal file
16
test/Macros/print_clang_expand_on_imported_objc.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// REQUIRES: swift_swift_parser, executable_test, objc_interop, concurrency
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// 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
|
||||
|
||||
// Build the macro library to give us access to AddAsync.
|
||||
// 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)
|
||||
|
||||
// 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
|
||||
// RUN: %FileCheck -input-file %t/imported.printed.txt %s
|
||||
|
||||
import CompletionHandlerGlobals
|
||||
|
||||
// CHECK: class Computer
|
||||
// FIXME: The "open" is odd here. We want this to be "final", but can't yet.
|
||||
// CHECK: open func multiply(_ x: Double, by y: Double) async -> Double
|
||||
Reference in New Issue
Block a user