Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13711] UnknownExpr in parse tree when an expression contains an attributed type #56108

Closed
allevato opened this issue Oct 8, 2020 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@allevato
Copy link
Collaborator

allevato commented Oct 8, 2020

Previous ID SR-13711
Radar rdar://problem/70101520
Original Reporter @allevato
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS 10.15.5, Swift 5.3 (Xcode 12.0)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @rintaro
Priority Medium

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 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.)

@typesanitizer
Copy link

@swift-ci create

@rintaro
Copy link
Mannequin

rintaro mannequin commented Oct 12, 2020

#34257

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants