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-3671] Terrible diagnostics for providing a getter and an initial value for a property #46256

Closed
belkadan opened this issue Jan 18, 2017 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation parser Area → compiler: The legacy C++ parser

Comments

@belkadan
Copy link
Contributor

Previous ID SR-3671
Radar None
Original Reporter @belkadan
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, Parser
Assignee @jtbandes
Priority Medium

md5: 708c596adf9d48b60af8d9e129fd140e

Issue Description:

struct S1 {
  var v = 1 {
    get {                   // report Error: Use of unresolved identifier ‘get'
      return self.v    // report Error: Use of unresolved identifier ‘self'
    }
  }
}
<stdin>:3:5: error: use of unresolved identifier 'get'
    get {                   // report Error: Use of unresolved identifier ‘get'
Swift.Set:139:15: note: did you mean 'Set'?
public struct Set<Element> : SetAlgebra, Hashable, Collection, ExpressibleByArrayLiteral where Element : Hashable {
              ^
<stdin>:4:14: error: use of unresolved identifier 'self'
      return self.v    // report Error: Use of unresolved identifier ‘self'

We should parse the getter like an observing accessor, then diagnose it specifically and throw it away.

@jtbandes
Copy link
Collaborator

jtbandes commented Feb 2, 2017

Interestingly, the braced block after 1 seems to be parsed as a trailing closure to the Int initializer. Trailing closures probably shouldn't be parsed at all after literals. But it's interesting to note that trailing closures may generally be valid in this position; to improve these diagnostics in general might require peeking into the closure.

@jtbandes
Copy link
Collaborator

jtbandes commented Feb 2, 2017

#7202

@belkadan
Copy link
Contributor Author

belkadan commented Feb 2, 2017

I'm tempted to leave this open to specifically check for get and set like we do willSet and didSet, even with @rintaro's example that shows it can sometimes be valid code. See isStartOfGetSetAccessor.

@jtbandes
Copy link
Collaborator

jtbandes commented Feb 3, 2017

I'll take look at further improvements this evening. Feel free to reopen if you want.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

2 participants