Uploaded image for project: 'Swift'
  1. Swift
  2. SR-6211

type-inference fails through Optionals

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:

      Description

      this small example program

      public struct Bar {
          public init?() {
              return nil
          }
      }
      
      let x: Bar = .init()!
      let y: Bar? = .init()
      

      should even with Swift's local-only type-inference be inferred I believe, however the type-checker fails on both x and y :'(

      test2.swift:7:21: error: type of expression is ambiguous without more context
      let x: Bar = .init()!
                   ~~~~~~~^
      test2.swift:8:16: error: value of optional type 'Bar' not unwrapped; did you mean to use '!' or '?'?
      let y: Bar? = .init()
                     ^
                           !
      

      for

      $ swiftc --version
      Apple Swift version 4.0.1 (swiftlang-900.0.66 clang-900.0.37)
      Target: x86_64-apple-macosx10.9
      

      and

      Apple Swift version 4.1-dev (LLVM f35a4270ce, Clang bb20a94e86, Swift e4ddd564b9)
      Target: x86_64-apple-darwin17.2.0
      

        Attachments

          Activity

            People

            Assignee:
            xedin Pavel Yaskevich
            Reporter:
            jw Johannes Weiss
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: