Skip to content

Commit 6bf6c0b

Browse files
authored
Merge pull request #64274 from DougGregor/macro-warning-error-decls
2 parents faebc16 + e13b104 commit 6bf6c0b

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ endif()
290290
list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-experimental-concise-pound-file")
291291

292292
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Macros")
293+
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "FreestandingMacros")
293294

294295
if(SWIFT_CHECK_ESSENTIAL_STDLIB)
295296
add_swift_target_library(swift_stdlib_essential ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB IS_STDLIB_CORE

stdlib/public/core/Macros.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,12 @@ public macro dsohandle() -> UnsafeRawPointer = Builtin.DSOHandleMacro
9393
public macro OptionSet<RawType>() =
9494
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
9595

96+
/// Produce the given warning message during compilation.
97+
@freestanding(declaration)
98+
public macro warning(_ message: String) = Builtin.WarningMacro
99+
100+
/// Produce the given error message during compilation.
101+
@freestanding(declaration)
102+
public macro error(_ message: String) = Builtin.ErrorMacro
103+
96104
#endif

test/IDE/complete_pound_expr.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ func test1() {
1515
let _ = useSelector(##^POUND_EXPR_3^#)
1616
}
1717

18-
// POUND_EXPR_INTCONTEXT: Begin completions, 8 items
18+
// POUND_EXPR_INTCONTEXT: Begin completions, 10 items
1919
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: function[#ExpressibleByStringLiteral#]; name=function
20+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: warning({#(message): String#})[#Void#]; name=warning(:)
21+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: error({#(message): String#})[#Void#]; name=error(:)
2022
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: fileID[#ExpressibleByStringLiteral#]; name=fileID
2123
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: file[#ExpressibleByStringLiteral#]; name=file
2224
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: dsohandle[#UnsafeRawPointer#]; name=dsohandle
@@ -26,8 +28,10 @@ func test1() {
2628
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: filePath[#ExpressibleByStringLiteral#]; name=filePath
2729
// POUND_EXPR_INTCONTEXT: End completions
2830

29-
// POUND_EXPR_STRINGCONTEXT: Begin completions, 9 items
31+
// POUND_EXPR_STRINGCONTEXT: Begin completions, 11 items
3032
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: function[#ExpressibleByStringLiteral#]; name=function
33+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: warning({#(message): String#})[#Void#]; name=warning(:)
34+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: error({#(message): String#})[#Void#]; name=error(:)
3135
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: fileID[#ExpressibleByStringLiteral#]; name=fileID
3236
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: file[#ExpressibleByStringLiteral#]; name=file
3337
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: dsohandle[#UnsafeRawPointer#]; name=dsohandle
@@ -38,8 +42,10 @@ func test1() {
3842
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: externalMacro({#module: String#}, {#type: String#})[#T#]; name=externalMacro(module:type:)
3943
// POUND_EXPR_STRINGCONTEXT: End completions
4044

41-
// POUND_EXPR_SELECTORCONTEXT: Begin completions, 9 items
45+
// POUND_EXPR_SELECTORCONTEXT: Begin completions, 11 items
4246
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: function[#ExpressibleByStringLiteral#]; name=function
47+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: warning({#(message): String#})[#Void#]; name=warning(:)
48+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: error({#(message): String#})[#Void#]; name=error(:)
4349
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: fileID[#ExpressibleByStringLiteral#]; name=fileID
4450
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: file[#ExpressibleByStringLiteral#]; name=file
4551
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: dsohandle[#UnsafeRawPointer#]; name=dsohandle

0 commit comments

Comments
 (0)