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-8811] Diagnosing Implicit Accessors for Uninhabited Types Should Be Smarter #51319

Open
CodaFi opened this issue Sep 20, 2018 · 3 comments
Open
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement SIL

Comments

@CodaFi
Copy link
Member

CodaFi commented Sep 20, 2018

Previous ID SR-8811
Radar None
Original Reporter @CodaFi
Type Improvement
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, SILDiagnostics, StarterBug
Assignee None
Priority Medium

md5: fe8546f9296464e8c547c7c953e07a35

Issue Description:

Try to emit SIL for the following code

enum Empty {}

class Foo {
  var x: Empty // function with uninhabited return type 'Empty' is missing call to another never-returning function on all paths

  init(_ x: Empty) {
    self.x = x
  }
}

It's good that we error, it's dismaying that we're diagnosing an implicit declaration. In particular, we're diagnosing the getter. We should check for accessors and emit something specialized here.

@belkadan
Copy link
Contributor

Alternately, we could change SILGen to emit a trap as the body of the function.

…actually, we should probably just change Sema to disallow a stored property with uninhabited type, since the rest of the language won't stop you from trying to call the getter. You can already see how silly it is in the initializer, which tries to set it.

@Azoy
Copy link
Member

Azoy commented Oct 26, 2018

This is resolved here: #19992

@jckarter
Copy link
Member

Making it an error to define a variable with uninhabited types is not the correct fix. The diagnostic in the getter is a bug; since it should already be unreachable to have a struct or class instance with an uninhabited stored property, the getter is already impossible to call, and we should not emit any reachability diagnostics for it. Maybe this could be a warning, but it should not be an error to declare a variable or property with uninhabited type.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added diagnostics QoI Bug: Diagnostics Quality of Implementation SIL and removed SILDiagnostics labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement SIL
Projects
None yet
Development

No branches or pull requests

5 participants