From 8ed06a43649e26a30cdde3f3472a12ea8a1628e3 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Sun, 23 Jun 2024 07:36:16 -0700 Subject: [PATCH] Properly deprecate default implementation of `MacroExpansionContext.lexicalContext` Now that we have, we can change the default implementation of `MacroExpansionContext.lexicalContext` to return an empty array and be deprecated, making not implementing `lexicalContext` a compile-time warning instead of a runtime error. rdar://123410459 --- Sources/SwiftSyntaxMacros/MacroExpansionContext.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/SwiftSyntaxMacros/MacroExpansionContext.swift b/Sources/SwiftSyntaxMacros/MacroExpansionContext.swift index 586ae269aaf..450e3a5d037 100644 --- a/Sources/SwiftSyntaxMacros/MacroExpansionContext.swift +++ b/Sources/SwiftSyntaxMacros/MacroExpansionContext.swift @@ -88,11 +88,18 @@ extension MacroExpansionContext { return location(of: node, at: .afterLeadingTrivia, filePathMode: .fileID) } + #if compiler(>=6.0) + @available(*, deprecated, message: "`MacroExpansionContext` conformance must implement `lexicalContext`") + public var lexicalContext: [Syntax] { + return [] + } + #else public var lexicalContext: [Syntax] { fatalError( "`MacroExpansionContext` conformance must implement `lexicalContext`" ) } + #endif } /// Diagnostic message used for thrown errors.