Swift: Spurious “variable used within its own initial value” error when shadowing constant w/ parameter

Originator:rix.rob
Number:rdar://17315832 Date Originated:14-Jun-2014 03:12 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta (6A215l)
Classification:Serious Bug Reproducible:Always
 
Summary:
Assigning to a constant with the result of a closure which includes a parameter of the same name results in a spurious error.

Steps to Reproduce:
Attempt to compile these two functions:

func with<T, U>(value: T, f: (T) -> U) -> U {
	return f(value)
}

func without() {
	let foo: Int = with(1) { (foo: Int) -> Int in
		let bar = foo * 2
		return bar
	}
}


Expected Results:
I expected that it would compile. The closure in `without` has a parameter by the name of foo which ought to be shadowing the constant it is initializing.


Actual Results:
The use of foo in an expression is apparently being matched up with the constant and not the parameter.


Regression:
N/A


Notes:
Note that if you just return foo, you don’t get an error.

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!