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

Discarding a function from a discardableResult method causes a compiler error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Environment:

      Swift version 4.2-dev (LLVM 95345677bd, Clang daefc772c1, Swift 76c264e9a1)
      Target: x86_64-apple-darwin17.4.0

      Description

      This example doesn't compile:

      struct S {
        @discardableResult
        func foo() -> () -> String { fatalError() }
      }
      
      let s = S()
      s.foo() // error: Expression resolves to an unused function
      

      But really it should. Interestingly enough it does compile if it's a top-level function:

      @discardableResult
      func foo() -> () -> String { fatalError() }
      
      foo()
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mininny Minhyuk Kim
              Reporter:
              originaluser2 Hamish Knight
              Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: