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

Segmentation fault: 11 (related to dynamically querying conditional conformance?)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Environment:

      Description

      The following code produces Segmentation fault: 11 on runtime after building with swiftc 4.2:

       

      import Darwin
      
      private protocol AnyChangeTracker {
          var myVariable: Any? { get }
          var isModified: Bool { get }
      }
      
      protocol ChangeTrackerType {
          associatedtype Value
          var originalValue: Value { get }
          var value: Value { get set }
          var isModified: Bool { get }
      }
      
      extension ChangeTrackerType where Value: Equatable {
          var isModified: Bool {
      	return value != originalValue
          }
      }
      
      struct ChangeTracker<T: Equatable>: ChangeTrackerType {
          let originalValue: T
          var value: T
      
          init(value: T) {
      	originalValue = value
      	self.value = value
          }
      }
      
      extension ChangeTracker: AnyChangeTracker where Value: OptionalType, Value.Wrapped: Equatable {
          var myVariable: Any? {
      	return value
          }
      }
      
      protocol OptionalType {
          associatedtype Wrapped
          var value: Wrapped? { get }
      }
      
      extension Optional: OptionalType {
          var value: Wrapped? {
      	return self
          }
      }
      
      let s: Any = ChangeTracker<String?>(value: "Foo")
      
      guard let s = s as? AnyChangeTracker else {
          print("Does not comply to AnyChangeTracker")
          exit(0)
      }
      
      print(s.myVariable ?? "nil")
      

      When building with swiftc 4.1.2, running produces the warning

      warning: Swift runtime does not yet support dynamically querying conditional conformance ('Crash.ChangeTracker<Swift.Optional<Swift.String>>': 'Crash.(AnyChangeTracker in _A1D8A7F4C436C7DDBF73EA9DCC81F3E0)')
      

      and typecasting fails

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              HumZ Jeremy Boy
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: