-
Notifications
You must be signed in to change notification settings - Fork 459
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
Enum generation can make code that causes new Swift 5.1 error message #904
Comments
|
Capturing it since we've been discussing it locally -
|
Also, just switching this test file to proto2 syntax doesn't make it work, there are enough cases even without the one having an associated value to still cause a the issue. |
This is a workaround for apple#904, the underlying problem is still there, but this makes the generated source file for testing "work" in that it doesn't hit the compile failure. A real solution is still needed for large enums.
This is a workaround for #904, the underlying problem is still there, but this makes the generated source file for testing "work" in that it doesn't hit the compile failure. A real solution is still needed for large enums.
Jordan Rose recommended filing a new bug since the original one was resolved, so let's track https://bugs.swift.org/browse/SR-11533 now. |
So about the only thing we seem to be able to come up with is do something like: var rawValue: Int {
switch self {
case .case0: return 0
case .case1: return 1
case .case2: return 2
case .case3: return 3
case .case4: return 4
case .case5: return 5
// ...
case .caseN: return N
default: break // nothing
}
switch self {
case .caseN_1: return N+1
case .caseN_2: return N+2
case .caseN_3: return N+3
case .caseN_4: return N+4
case .caseN_5: return N+5
// ...
case .case2N: return 2*N
default: break // nothing
}
// ...
if case let .UNRECOGNIZED(i) == self { return i }
// Can't get here, all the cases are listed above.
// See https://github.com/apple/swift-protobuf/issues/904 for more.
fatalError()
} The The downsides being, this likely generates extra code because it isn't a single |
On the other hand, that |
And even that logic was overly complex. All we need is if over the limit, append a default and then throw the fatalError after it. done. The presence of the default avoid the compiler issue, no reason to use multiple switches, etc. |
And that doesn't work, if you add the |
This works around the compiler issue by adding the default and having more than one switch with none being complete. Fixes apple#904
A .proto file with an enum with a lot of cases ends up needing to generate
switch
statements with a lot ofcase
s. As of Swift 5.1 this can cause the compiler to actually error out.SwiftProtobuf sees this itself with one of the
generated_swift_names_*.swift
files:On the near/short term, we need to do something to tweak what the validation generates to work around this, but…
Longer term, we likely need to see if something can be generated differently/annotate the source in some way to avoid this problem.
The text was updated successfully, but these errors were encountered: