Allow parameters to default to the value of earlier parameters

Arbitrary code with side effects is already allowed. I can get this nonsense to compile:

func test(_ t: Void = FileManager.setDefaultPlaceholder(nil, forMarker: nil, withBinding: .alignment)) {
	/* ... */
}

You can call functions in default values, and you can use operators. You just can't reference self or other parameters of the current function.

If some day we add the concept of a pure function, we'll need to restrict default values of pure functions to a pure expression (something I need to add in my exploratory proposal), but I think that ship has already sailed for regular (non-pure) functions.

4 Likes