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

Runtime assertion hit when using an 'deallocated' unowned reference in a -O build

    XMLWordPrintable

    Details

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

      Swift version 5.0-dev (LLVM 6ddb64316c, Swift d17602a847)
      Target: x86_64-apple-darwin18.2.0

      Description

      In a -O build, the following trips a runtime assertion:

      import Dispatch
      import Foundation
      
      func foo() {
        class MyObject {
          var value = 0
        }
      
        var o = MyObject()
        unowned var u = o
        o = MyObject()
      
        DispatchQueue.main.asyncAfter(deadline: .now()) {
          print("old unowned u = \(u)")
        }
      }
      foo()
      
      RunLoop.main.run()
      

      Output:

      ./swiftc /Users/hamishknight/Desktop/Stochastic\ Projects/unowned\ unowned/unowned\ unowned/main.swift -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -O; and ./main
      /Users/hamishknight/Desktop/Stochastic Projects/unowned unowned/unowned unowned/main.swift:18:15: warning: variable 'u' was never mutated; consider changing to 'let' constant
        unowned var u = o
                ~~~ ^
                let
      Assertion failed: (object->refCounts.getUnownedCount() && "object is not currently unowned-retained"), function swift_unownedRetainStrong, file /Users/hamishknight/Desktop/swift-dev/swift/stdlib/public/runtime/HeapObject.cpp, line 516.
      fish: './main' terminated by signal SIGABRT (Abort)
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            originaluser2 Hamish Knight
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: