On Wed, May 4, 2016, at 10:41 AM, Jan E. Schotsman via swift-users
wrote:
> Hello,
> 
> This code causes a segmentation fault:
> 
> struct MyHeapElement<T:Comparable>
>       {
>       var index:Int
>       var     key:T
>       }
> 
> struct MyHeap<T:Comparable>
>       {
>       var elements = [MyHeapElement<T>]()
>       }
> 
> extension MyHeap
>       {
>       init( withElements elements:[MyHeapElement<T>] )
>               {
>               self.elements = elements
>               }
>       }
> 
> Do I have a syntax error somewhere or is this a compiler bug (apart  
> from that ideally the compiler should never crash)?
> 
> Swift 2.1-2.2
> 
> Jan E.
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

Drop the extension and move the initializer to the MyHeap struct and it
compiles for me on Swift 3.0. To me that indicates the answer to your
first question: I would think you do not have a syntax error. That is:

struct MyHeapElement <T:Comparable> {
  var index: Int
  var key: T
}

struct MyHeap <T:Comparable> {
  var elements = [MyHeapElement<T>]()

  init(withElements elements: [MyHeapElement<T>]) {
    self.elements = elements
  }
}

Regardless of whether it is or not you should file the bug at
bugs.swift.org. As you say the compiler should never crash.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to