Skip to content

Commit

Permalink
Work around an ASTVerifier failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
hborla committed Feb 1, 2023
1 parent 01ba9f3 commit 7b4ff26
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions MacroExamples/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ let y = 2
let z = 3

// "Stringify" macro turns the expression into a string.
print(#stringify(x + y))

func testStringify() {
print(#stringify(x + y))
}
// "AddBlocker" complains about addition operations. We emit a warning
// so it doesn't block compilation.
print(#addBlocker(x * y + z))

#myWarning("remember to pass a string literal here")
func blockAdd() {
print(#addBlocker(x * y + z))
}

func produceWarning() {
#myWarning("remember to pass a string literal here")
}
// Uncomment to get an error out of the macro.
// let text = "oops"
// #myWarning(text)
Expand All @@ -24,4 +28,11 @@ struct Font: ExpressibleByFontLiteral {
}
}

let font: Font = #fontLiteral(name: "Comic Sans", size: 14, weight: .thin)
func testFontLiteral() {
let font: Font = #fontLiteral(name: "Comic Sans", size: 14, weight: .thin)
}

testStringify()
blockAdd()
produceWarning()
testFontLiteral()

0 comments on commit 7b4ff26

Please sign in to comment.