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

Conditional Conformance Crash on type casting

    XMLWordPrintable

    Details

      Description

      I have a similar code in my project.

      /// playground
      protocol RealtimeValue {}
      protocol WritableRealtimeValue: RealtimeValue {}
      protocol ChangeableRealtimeValue: RealtimeValue {}
      protocol RealtimeCollection: RealtimeValue {}
      
      class _RealtimeValue: RealtimeValue {}
      
      
      class Object: _RealtimeValue {}
      
      
      class __RepresentableCollection<Element: RealtimeValue, Ref: RealtimeValue>: _RealtimeValue, RealtimeCollection {}
      extension __RepresentableCollection: WritableRealtimeValue where Ref: WritableRealtimeValue {}
      
      
      struct RCItem: WritableRealtimeValue {}
      
      
      class References<Element: RealtimeValue>: __RepresentableCollection<Element, RCItem> {}
      
      
      let _references: _RealtimeValue = __RepresentableCollection<Object, RCItem>()
      /// uncomment and crash won't be
      //_references as? WritableRealtimeValue
      
      
      let references: _RealtimeValue = References<Object>()
      references as? WritableRealtimeValue // crash

      The same happened in regular Xcode project with disabled optimizations.
      Crash description:

      error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT).
      The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
      
      
      * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
        * frame #0: 0x000000011ac1b3aa libswiftCore.dylib`swift_getObjCClassMetadata + 26
          frame #1: 0x000000011ac2ddd9 libswiftCore.dylib`searchInConformanceCache(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 57
          frame #2: 0x000000011ac2d908 libswiftCore.dylib`swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 56
          frame #3: 0x000000011ac0c3a6 libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 38
          frame #4: 0x000000011ac2d250 libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, llvm::function_ref<swift::TargetMetadata<swift::InProcess> const* (unsigned int)>, llvm::function_ref<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>) + 416
          frame #5: 0x000000011ac2d044 libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const + 244
          frame #6: 0x000000011ac2e088 libswiftCore.dylib`swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*)::$_3::operator()(swift::TargetProtocolConformanceDescriptor<swift::InProcess> const&, swift::TargetMetadata<swift::InProcess> const*) const + 232
          frame #7: 0x000000011ac2db19 libswiftCore.dylib`swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 585
          frame #8: 0x000000011ac0c3a6 libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 38
          frame #9: 0x000000011ac120d5 libswiftCore.dylib`_conformsToProtocols(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 213
          frame #10: 0x000000011ac10dc6 libswiftCore.dylib`_dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 422
          frame #11: 0x000000011dcb621a $__lldb_expr94`main at Untitled Page 2.xcplaygroundpage:26
          frame #12: 0x0000000104e705f0 Whats-New-In-Swift-4-2`linkResources + 304
          frame #13: 0x00000001066ea62c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
          frame #14: 0x00000001066e9de0 CoreFoundation`__CFRunLoopDoBlocks + 336
          frame #15: 0x00000001066e4654 CoreFoundation`__CFRunLoopRun + 1284
          frame #16: 0x00000001066e3e11 CoreFoundation`CFRunLoopRunSpecific + 625
          frame #17: 0x000000010b0dd1dd GraphicsServices`GSEventRunModal + 62
          frame #18: 0x000000010bbb381d UIKitCore`UIApplicationMain + 140
          frame #19: 0x0000000104e706bd Whats-New-In-Swift-4-2`main + 205
          frame #20: 0x000000010810d575 libdyld.dylib`start + 1
          frame #21: 0x000000010810d575 libdyld.dylib`start + 1
      

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            k-o-d-e-n Denis Koryttsev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: