[SR-11471] Type-inferred call to optional initializer yields no-win errors and incorrect fixits #53871
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
type checker
Area → compiler: Semantic analysis
Environment
Xcode Version 11.0 (11A419c)
Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin19.0.0
Additional Detail from JIRA
md5: f4da30a0271ce9b92a0ef9f5d12c95c3
Issue Description:
When an expression such as
return .init(rawValue: "whatever")
infers an optional initializer on the decided type (such as for aRawRepresentable
structure), the compiler will demand the optional be unwrapped, but unwrapping it just results in a complaint that a non-optional type is being unwrapped. A bit ridiculously, accepting the fixit to use the nil-coalescing operator results in even more contradictions in the errors. Per the following REPL session:Adding
Self
or the real type name before or in place of the.init
satisfies the compiler:(Note: My original code was more verbose, e.g.:
The results were the same with or without the additional syntax.)
The text was updated successfully, but these errors were encountered: