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-5852] Compilation failure for overloaded enum initializers with whole module optimization turned on #48422

Open
allenhumphreys opened this issue Sep 7, 2017 · 2 comments
Labels
compiler The Swift compiler in itself

Comments

@allenhumphreys
Copy link

allenhumphreys commented Sep 7, 2017

Previous ID SR-5852
Radar rdar://problem/34295485
Original Reporter @allenhumphreys
Type Sub-task

Attachment: Download

Environment

```
swiftc --version
Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Target: x86_64-apple-macosx10.9
```

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Sub-task
Assignee None
Priority Medium

md5: 8ff64ffe67c51133465e3d6c3f6367e1

Parent-Task:

Issue Description:

This bug has a complicated set of prerequisites to produce.

  1. wmo is turned on swiftc -O -whole-module-optimization ProxyStruct.swift main.swift
@belkadan
Copy link
Contributor

belkadan commented Sep 7, 2017

Reproduced. Very strange! Thanks, Allen.

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented Sep 8, 2017

Reduced:

// ProxyStruct.swift
enum SecondEnum: String {
  case one
  init(rawValue: RawValue?) {
    fatalError()
  }
}

func g(secondEnumString: String?) {
  SecondEnum(rawValue: secondEnumString)
}

// main.swift
func f(proxy: SecondEnum?) {
  _ = proxy?.rawValue
}

Manually writing out a RawRepresentable conformance has funny behavior, e.g. this works (as does adding typealias RawValue = String to the original code)

enum SecondEnum: RawRepresentable {
  case one
  typealias RawValue = String
  var rawValue: RawValue { return "" }
  init?(rawValue: RawValue) {
    fatalError()
  }
  init(rawValue: RawValue?) {
    fatalError()
  }
}

But these two (relying on associated type inference) don't:

enum SecondEnum: RawRepresentable {
  case one
  var rawValue: String { return "" }
  init?(rawValue: RawValue) {
    fatalError()
  }
  init(rawValue: RawValue?) {
    fatalError()
  }
}
// error: cannot invoke initializer for type 'SecondEnum' with an argument list of type '(rawValue: String?)'

enum SecondEnum: RawRepresentable {
  case one
  var rawValue: String { return "" }
  init?(rawValue: String) {
    fatalError()
  }
  init(rawValue: RawValue?) {
    fatalError()
  }
}
// error: value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

2 participants