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-6996] Better diagnostic when declaring a class with parentheses #49544

Closed
swift-ci opened this issue Feb 14, 2018 · 8 comments
Closed

[SR-6996] Better diagnostic when declaring a class with parentheses #49544

swift-ci opened this issue Feb 14, 2018 · 8 comments
Labels

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 14, 2018

Previous ID SR-6996
Radar None
Original Reporter rgov (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, Parser, StarterBug
Assignee Kazutaka333 (JIRA)
Priority Medium

md5: 4a7df1509b4bcd5ea816866a6676cef6

Issue Description:

Switching between Python and Swift, I accidentally wrote: class Foo() { ... }

This generated a handful of diagnostics on one line, including:

  • Closure expression is unused (Did you mean to use a 'do' statement?)

  • Expecting '{' in class

  • Expressions are not allowed at the top level

  • Top-level statement cannot begin with a closure expression

Xcode decides to show the "closure expression" diagnostic instead of the second one, which is the closest to being to right thing to show. But it might be nice to have a special diagnostic for this.

@belkadan
Copy link
Contributor

belkadan commented Feb 14, 2018

Seems reasonable. @rintaro, think this would make a good starter bug?

@rintaro
Copy link
Mannequin

rintaro mannequin commented Feb 21, 2018

Yeah, this is good StarterBug 🙂

For those who want to tackle this task:
The start point is here https://github.com/apple/swift/blob/6095dc95/lib/Parse/ParseDecl.cpp#L5652 .
Normally, if the current token is colon ':', we parse inheritance clause.

Add another branch like:

if (Tok.is(tok::colon)) {
   ...
} else if (Tok.is(tok::l_paren)) {
  // if the following tokens looks like a type and followed by ')',
  // treat it as Python style inheritance clause.
  // Offer a fix-it to replace '(' with ': ' and remove ')'.
}

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 3, 2018

Comment by Ryosuke Iwanaga (JIRA)

I'm going to tackle this.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 3, 2018

Comment by Kazutaka Homma (JIRA)

riywo (JIRA User) I've been working on this since a few days ago

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 3, 2018

Comment by Ryosuke Iwanaga (JIRA)

Got it, I gave up.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 3, 2018

Comment by Kazutaka Homma (JIRA)

riywo (JIRA User) I think you could work on a task with no assignee.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 3, 2018

Comment by Kazutaka Homma (JIRA)

I'm thinking that I should define a new Error message in DiagnosticsParse.def for this specific case. What I came up with so far is the following message.

"expected ':' before inheritance identifier"

However, I'm not sure this is the best. Is there any better idea?

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 9, 2018

Comment by Kazutaka Homma (JIRA)

Merged

#15010

@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
Projects
None yet
Development

No branches or pull requests

2 participants