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:
Doug Gregor
2024-09-16 15:39:29 -07:00
parent ead028bb11
commit 593f1dedb0
5 changed files with 50 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View 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)
}

View File

@@ -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

View 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