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

`KeyPath.appending` crashes when appending to an objc variable

    XMLWordPrintable

    Details

      Description

      The code snippet below crashes if you run it a few times on the iPhone XS simulator. I've also attached a sample project demonstrating the issue.

      Changing the name of the var with the ``s in it can cause the crash to occur more or less often. I'm not actually sure if the `` is directly responsible, but since it seems to have a special significance in name mangling, I assume that the objc selector is name-mangled, and the code for `appending` seems to be doing some kind of manipulation of the selector name I'm guessing it's related. 

      The crash is usually similar to what's reproduced below:

      KeyPathTest(97433,0x700004484000) malloc: Heap corruption detected, free list is damaged at 0x60000006eb50
      *** Incorrect guard value: 34080200846080
      KeyPathTest(97433,0x700004484000) malloc: *** set a breakpoint in malloc_error_break to debug
      
      import UIKit
      
      func test() {
          // In my real app, it usually breaks immediately on the first run,
          // but in the sample app I had to run the code several times before it would crash.
          for _ in 0..<1000 {
              print((\Theme.snek_lll_ll).appending(path: \ColorSplash.camelCaseVar))
              
          }
      }
      
      @objc
      public protocol Theme: AnyObject {
          
          var snek_lll_ll: ColorSplash { get }
          
      }
      
      public class ColorSplash: NSObject {
          
          @objc
          public var camelCaseVar: UIColor {
              return .white
          }
          
      }
      
      

        Attachments

          Activity

            People

            Assignee:
            mikeash Mike Ash
            Reporter:
            benpious Ben Pious
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: