Swift 1.2b3: `case let Case` without bindings incorrectly matches other cases

Originator:rix.rob
Number:rdar://20253447 Date Originated:22-Mar-2015 05:57 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (6D543q)
Classification:Serious Bug Reproducible:Always
 
Summary:



Steps to Reproduce:
1. Run this:

	enum Tree: Printable {
		case Leaf(Int)
		case Branch(Int, [Tree])

		var children: [Tree] {
			switch self {
			case let Leaf:
				return []
			case let Branch(_, children):
				return children
			}
		}

		var description: String {
			switch self {
			case let Leaf(x):
				return ".Leaf(\(x))"
			case let Branch(x, children):
				let c = ",\n\t".join(map(children, toString))
				return ".Branch(\(x), [\n\t\(c)\n])"
			}
		}
	}

	let branch = Tree.Branch(1, [Tree.Leaf(2), Tree.Leaf(3)])
	println(branch.children)


Expected Results:
[.Leaf(2), .Leaf(3)]


Actual Results:
[]


Regression:
Workarounds:

1. Use a pattern after the constructor name:
	case let Leaf(_):
2. Remove `let`:
	case Leaf:

Notes:
This is incredibly serious. It’s trivial to accidentally use `let` when you’re not actually binding anything, and it will completely mask this error. I’m frankly astonished I haven’t encountered this before—I can only assume that’s because I usually bind all of the variables. Or maybe I _have_, and missed the bug. That’s pretty scary.

Comments

Duped as rdar://20258603

By heath.borders at March 23, 2015, 4:01 p.m. (reply...)

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!