Files
swift-mirror/test/Macros/macro_expand_other.swift
2025-09-18 16:41:07 -07:00

53 lines
1.8 KiB
Swift

// Expanding macros that are defined in terms of other macros.
// RUN: %empty-directory(%t)
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift
// Diagnostics testing
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS
// Execution testing
// RUN: %target-build-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -o %t/main -module-name MacroUser
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s
// REQUIRES: swift_swift_parser, executable_test
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
@freestanding(expression) macro stringifySeven() -> (Int, String) = #stringify(7)
@freestanding(expression) macro recurse(_: Bool) = #externalMacro(module: "MacroDefinition", type: "RecursiveMacro")
@freestanding(expression) macro recurseThrough(_ value: Bool) = #recurse(value)
func testFreestandingExpansionOfOther() {
// CHECK: ---testFreestandingExpansionOfOther
print("---testFreestandingExpansionOfOther")
// CHECK-NEXT: (7, "7")
print(#stringifySeven)
#recurseThrough(false)
#if TEST_DIAGNOSTICS
#recurseThrough(true)
/*
expected-expansion@-2:1{{
expected-expansion@1:1{{
expected-error@1:1{{recursive expansion of macro 'recurse'}}
}}
expected-note@1:1{{in expansion of macro 'recurse' here}}
}}
expected-note@-8 {{in expansion of macro 'recurseThrough' here}}
*/
#endif
}
@freestanding(expression)
macro myLineMacro() -> Int = #line
var thisLine = #myLineMacro
testFreestandingExpansionOfOther()