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

Property wrapper with initializer accepting closure and any additional argument causes segmentation fault

    XMLWordPrintable

    Details

      Description

      This code causes "Segmentation fault: 11" error on the latest Xcode 12 beta

      @propertyWrapper
      struct MyWrapper<T> {
          let defaultValue: () -> T
          let key: String
          
          init(wrappedValue: @escaping @autoclosure () -> T, key: String) {
              self.defaultValue = wrappedValue
              self.key = key
          }
      
          var wrappedValue: T {
              get { self.defaultValue() }
              set {}
          }
      }
      
      struct MyStruct {
          @MyWrapper(key: "int")
          var int = 0
      }

      The error disappears in following cases:

      1. Not using closures and just passing wrappedValue as is
      2. Removing second init argument
      3. Writing
      struct MyStruct {
          @MyWrapper(wrappedValue: 0, key: "int")
          var int: Int
      }
      

      instead of

      struct MyStruct {
          @MyWrapper(key: "int")
          var int = 0
      }

       

      Stack trace is attached below

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              acedened Vadim Novoseltsev
              Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: