510.0.0
版本发布时间: 2024-03-02 04:21:16
swiftlang/swift-syntax最新发布版本:600.0.0-prerelease-2024-09-04(2024-09-06 07:39:45)
New APIs
-
SyntaxStringInterpolation.appendInterpolation(_: (some SyntaxProtocol)?)
- Description: Allows optional syntax nodes to be used inside string interpolation of syntax nodes. If the node is
nil
, nothing will get added to the string interpolation. - Pull Request: https://github.com/apple/swift-syntax/pull/2085
- Description: Allows optional syntax nodes to be used inside string interpolation of syntax nodes. If the node is
-
SyntaxCollection.index(at:)
- Description: Returns the index of the n-th element in a
SyntaxCollection
. This computation is in O(n) andSyntaxCollection
is not subscriptable by an integer. - Pull Request: https://github.com/apple/swift-syntax/pull/2014
- Description: Returns the index of the n-th element in a
-
Convenience initializer
ClosureCaptureSyntax.init()
- Description: Provides a convenience initializer for
ClosureCaptureSyntax
that takes a concretename
argument and automatically addsequal = TokenSyntax.equalToken()
to it. - Issue: https://github.com/apple/swift-syntax/issues/1984
- Pull Request: https://github.com/apple/swift-syntax/pull/2127
- Description: Provides a convenience initializer for
-
Convenience initializer
EnumCaseParameterSyntax.init()
- Description: Provides a convenience initializer for
EnumCaseParameterSyntax
that takes a concretefirstName
value and addscolon = TokenSyntax.colonToken()
automatically to it. - Issue: https://github.com/apple/swift-syntax/issues/1984
- Pull Request: https://github.com/apple/swift-syntax/pull/2112
- Description: Provides a convenience initializer for
-
DiagnosticSeverity
andPluginMessage.Diagnostic.Severity
now have new case namedremark
- Description: Remarks are used by the Swift compiler and other tools to describe some aspect of translation that doesn't reflect correctness, but may be useful for the user. Remarks have been added to the diagnostic severity enums to align with the Swift compiler.
- Pull Request: https://github.com/apple/swift-syntax/pull/2143
Deprecations
-
Leaf Node Casts
- Description: Syntax nodes that do not act as base nodes for other syntax types have the casting methods marked as deprecated. This prevents unsafe type-casting by issuing deprecation warnings for methods that will always result in failed casts.
- Issue: https://github.com/apple/swift-syntax/issues/2092
- Pull Request: https://github.com/apple/swift-syntax/pull/2108
-
Same-Type Casts
- Description:
is
,as
, andcast
overloads onSyntaxProtocol
with same-type conversions are marked as deprecated. The deprecated methods emit a warning indicating the cast will always succeed. - Issue: https://github.com/apple/swift-syntax/issues/2092
- Pull Request: https://github.com/apple/swift-syntax/pull/2108
- Description:
-
Base Node Casts
- Description:
is
,as
, andcast
methods on base node protocols with base-type conversions are marked as deprecated. The deprecated methods emit a warning that informs the developer that the cast will always succeed and should be done using the base node's initializer. - Issue: https://github.com/apple/swift-syntax/issues/2092
- Pull Request: https://github.com/apple/swift-syntax/pull/2108
- Description:
-
WildcardPatternSyntax.typeAnnotation
- Description:
typeAnnotation
onWildcardPatternSyntax
was a mistake. UsetypeAnnotation
properties on the outer constructs instead. E.g.PatternBindingListSyntax.typeAnnotation
- Pull Request: https://github.com/apple/swift-syntax/pull/2393
- Description:
API-Incompatible Changes
-
NoteMessage.fixItID
renamed tonoteID
- Description: This was an error that it was named
fixItID
and should have been namednoteID
instead. Accesses tofixItID
are deprecated and forward tonoteID
. Any types that conformNoteMessage
it will need to be updated to provide anoteID
instead of afixItID
. - Issue: https://github.com/apple/swift-syntax/issues/2261
- Pull Request: https://github.com/apple/swift-syntax/pull/2264
- Description: This was an error that it was named
-
DiagnosticSpec.highlight
replaced byhighlights
- Description: The use of a single string
highlight
prevented users from asserting that a macro highlighted exactly the expected set of syntax nodes. Use ofDiagnosticSpec.init(...highlight:...)
is deprecated and forwards toDiagnosticSpec.init(...highlights:...)
. Migrating fromhighlight
tohighlights
is straightforward; any uses ofDiagnosticSpec.init
which do not specify ahighlight
do not need to change, otherwise:- If the diagnostic highlights a single node, the
highlight
string should be replaced with a single element array containing the same string without any trailing trivia, e.g.,highlight: "let "
->highlights: ["let"]
. - If the diagnostic highlights multiple nodes, the
highlight
string should be replaced with an array containing an element for each highlighted node, e.g.,highlight: "struct {}"
->highlights: ["struct", "{}"]
.
- If the diagnostic highlights a single node, the
- Pull Request: https://github.com/apple/swift-syntax/pull/2213
- Description: The use of a single string