Here's part of my expression macro code:
guard let literal = node.arguments.first?.expression(StringLiteralExprSyntax.self)
else {
throw .notStringLiteral
}
guard let string = literal.representedLiteralValue else {
throw .interpolationTermsPresent
}
When I run the test for the "interpolationTermsPresent", I get the wrong diagnostic. I get the one for "notStringLiteral".
@Test("Do not use string interpolation")
func noInterpolation() {
#if canImport(MyMacros)
assertMacroExpansion(
##"""
#myMacro(\("Helo"))
"""##,
expandedSource: """
0
""",
diagnostics: [
.init(
id: .init(
domain: "MyMacroType",
id: "contains-string-interpolation"
),
message: "String interpolation is not permitted.",
line: 1,
column: 1,
severity: .error
)
],
macros: testMacros
)
#endif
}
It's like the "\("Helo")" gets flagged as not-a-string before the interpolation checker sees it. What's going on?