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

Tiny code example that crashes recent development snapshots

    XMLWordPrintable

    Details

      Description

      Please see related discussion in this forums thread.

      Note that the same issue applies to willSet and set, and that I don't know if the compiler should allow this code or not, only that it shouldn't crash.

      // --------------------------------------------------------------------------
      // This program compiles with eg the default toolchain of Xcode 9.3 beta 4,
      // but crashes recent versions of the compiler (for example dev snapshot
      // 2018-02-25, 2018-03-13 and 2018-03-17, have only tested those three).
      // --------------------------------------------------------------------------
      var a: Int? {
          didSet { print("hello") }
      }
      a? = 123
      
      // --------------------------------------------------------------------------
      // Compiling and running with default toolchain of Xcode 9.3 beta 4:
      // --------------------------------------------------------------------------
      // › swiftc --version
      // Apple Swift version 4.1 (swiftlang-902.0.43 clang-902.0.37.1)
      // Target: x86_64-apple-darwin17.4.0
      // ›
      // › swiftc test.swift
      // › ./test
      // hello
      //
      // --------------------------------------------------------------------------
      // Compiling and running with development snapshot 2018-03-17:
      // --------------------------------------------------------------------------
      // › /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain/usr/bin/swiftc --version
      // Apple Swift version 4.2-dev (LLVM cef3fe6d75, Clang bdc970d89c, Swift 931d06d1cc)
      // Target: x86_64-apple-darwin17.4.0
      // ›
      // › /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain/usr/bin/swiftc test.swift
      // Assertion failed: (value && "No value specified"), function forUnmanaged, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILGen/ManagedValue.h, line 91.
      // 0  swift                    0x000000010aaee2c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
      // 1  swift                    0x000000010aaee9d6 SignalHandler(int) + 694
      // 2  libsystem_platform.dylib 0x00007fff6e86df5a _sigtramp + 26
      // ...
      

      Below is an additional demonstration of the same issue. But looking at this program, I think I'm pretty sure that I think it should be valid code, which perhaps means that the above example should be considered valid code too.
      (so, just to be very clear, this works as expected for def toolchain of Xc9.3b4 but crashes recent compilers):

      var x: Int? = 123 {
          willSet {
              print("willSet called:")
              print("    current value: \(String(describing: x))")
              print("        new value: \(String(describing: newValue))")
          }
      }
      print(String(describing: x))
      x?.negate()
      print(String(describing: x))
      

        Attachments

          Activity

            People

            Assignee:
            jens Jens Persson
            Reporter:
            jens Jens Persson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: