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

Type inference error when applying optional function to optional value

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Swift 4.0, Swift 4.0.1

      Description

      public extension Optional {
          public func apply<Result>(_ transform: ((Wrapped) -> Result)?) -> Result? {
              return self.flatMap { value in
                  transform.map { $0(value) }
              }
          }
      
          public func apply<Value, Result>(_ value: Value?) -> Result?
              where Wrapped == (Value) -> Result
          {
              return value.apply(self)
          }
      }

       

      Possibly related to bug: https://bugs.swift.org/browse/SR-6509

       

      This works fine under Swift3-3.2.

       

      Actual results:

      'apply' produces 'Result?', not the expected contextual result type 'Result?'

       

      Expected results:

      The code compiles, compiler infers the type of result for type of Wrapped

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              trimm Oleksandr Korin
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: