Crash in generic struct

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.

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.

···

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

That way I lose the memberwise initializer and the default initializer.
This is yet another crashing bug related to the position of an extension.

In December I reported this bug which looks similar:

bug 23998571

If the struct definition and the extension are placed in two different files of a framework project the compiler crashes.

struct Description
  {
  var property:Int32 = 0
  }

extension Description
  {
  init( startPtr: UnsafePointer<Int32> )
    {
      property = startPtr[0]
      }
  }

Still open, still crashing.

Jan E.

···

On May 4, 2016, at 5:02 PM, Ryan Lovelett wrote:

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.

bug 23998571

That number looks like a radar issue. Swift bugs typically take the form
SR-#.

I don't work at Apple (nor do many people on this mailing list).
Therefore we cannot see the contents of that bug report.

Once again I suggest you file an issue at bugs.swift.org as that is the
OSS community tracker.

As for losing the default initializer; I understand that may occur. I
was pointing out that it was my simple way of validating the syntax. It
may or may not work as a "work-around". It would appear it does not for
you.