You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an attributed type appears in an expression context, the parse tree contains an UnknownExpr even for valid code. This makes SwiftSyntax consumers fail if they attempt to treat any Unknown* nodes as syntactically invalid code.
The easiest way to reproduce this is to try to reference .self on an attributed function type:
let x = (@convention(c) (Int) -> Void).self
The following command emits a diagnostic:
echo 'let x = (@convention(c) Int -> Void).self' | swift -frontend -emit-syntax -
<stdin>:1:10: error: unknown expression syntax exists in the source
let x = (@convention(c) (Int) -> Void).self
^
But this command, where the actual AST is constructed instead of the parse tree, succeeds:
echo 'let x = (@convention(c) (Int) -> Void).self' | swift -
I've attached the pretty-printed JSON output as a separate file since it's somewhat large. The single child of the UnknownExpr (id 21) appears to be correct—it is an AttributedType containing a FunctionType, but since there is no *Expr node that is able to wrap an attributed type, it gets categorized as unknown instead. (Without the attribute, that wouldn't even be parsed as a type syntax, but instead as an ArrowExpr.)
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
macOS 10.15.5, Swift 5.3 (Xcode 12.0)
Additional Detail from JIRA
md5: 27798c66e3d897ecf71b22fbcbf6fcad
Issue Description:
When an attributed type appears in an expression context, the parse tree contains an
UnknownExpr
even for valid code. This makes SwiftSyntax consumers fail if they attempt to treat anyUnknown*
nodes as syntactically invalid code.The easiest way to reproduce this is to try to reference
.self
on an attributed function type:The following command emits a diagnostic:
But this command, where the actual AST is constructed instead of the parse tree, succeeds:
I've attached the pretty-printed JSON output as a separate file since it's somewhat large. The single child of the
UnknownExpr
(id 21) appears to be correct—it is anAttributedType
containing aFunctionType
, but since there is no*Expr
node that is able to wrap an attributed type, it gets categorized as unknown instead. (Without the attribute, that wouldn't even be parsed as a type syntax, but instead as anArrowExpr
.)The text was updated successfully, but these errors were encountered: