Segfault when compiling recursively defined indirect enums of a certain pattern.

Originator:regexident
Number:rdar://21961187 Date Originated:23-Jul-2015
Status:Open Resolved:
Product:Xcode Product Version:Version 7.0 beta 4 (7A165t)
Classification:Crash Reproducible:Always
 
Summary:

	Swiftc crashes with recursively defined indirect enums if they match a certain pattern.

Steps to Reproduce:

	Take this simple recursive binary tree:

	indirect enum PersistentBinaryTree<T> {
	    case Tail(left: PersistentBinaryTree, element: T, right: PersistentBinaryTree)
	    case Nil
	}
	=> Build successful

	Now add a function to it:

	indirect enum PersistentBinaryTree<T> {
	    case Tail(left: PersistentBinaryTree, element: T, right: PersistentBinaryTree)
	    case Nil
	    func foo() { }
	}

Expected Results:

	=> Build successful

Actual Results:

	=> Build failed. Command failed due to signal: Segmentation fault: 11

Regression:

	Here's the fun part: Change the order of parameters of the "Branch" case:

	indirect enum PersistentBinaryTree<T> {
	    case Tail(element: T, left: PersistentBinaryTree, right: PersistentBinaryTree)
	    case Nil
	    func foo() { }
	}
	=> Build successful

Notes:

	Same happens for PersistentList:

	indirect enum PersistentList<T> {
	    case Tail(head: T, tail: PersistentList)
	    case Empty
	    func foo() { }
	}
	=> Build successful

	indirect enum PersistentList<T> {
	    case Tail(tail: PersistentList, head: T)
	    case Empty
	    func foo() { }
	}
	=> Build failed. Command failed due to signal: Segmentation fault: 11

	Looks like indirect enums that have a recursive property at first position of a case AND functions segfault the compiler.

Update:

	Moving the "case Nil" above "case Branch(…)" (or "case Empty" above "case Tail(…)" respectively) makes the code compile, too.
	So for the segfault to trigger, a recursive property needs to be placed at the first position of the first case of a struct and it must have at least one function.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!