swiftc rejects `Self` in type parameters of expression chain in protocol extension

Originator:rix.rob
Number:rdar://23250756 Date Originated:25-Oct-2015 01:55 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1 (7B91b)
Classification:Serious Bug Reproducible:Always
 
Summary:
In protocol extensions can use `Self` as a parameter type, return type, type parameter, and typealias value, but not as a parameter in an expression chain like Optional<Self>.Some(…)


Steps to Reproduce:
1. This code:

protocol P {}

extension P {
	func f() -> Optional<Self> {
		return Optional<Self>.Some(self)
	}
}


Expected Results:
should compile without error


Actual Results:
but totally doesn’t:

boom.swift:7:23: error: '>' is not a postfix unary operator
                return Optional<Self>.Some(self)
                                    ^


Regression:
You can make a typealias whose value is Optional<Self> and use that on the left-hand side.


Notes:
I was trying to use this in a method returning Either<A, B<Self>> via a static function `with` with a trailing closure. There was some ill-typed expression in there and Swift decided to tell me I needed to disambiguate the type:

return .with { … }

so I wrote:

return Either<A, B<Self>>.with { … }

and got the stupid error above instead. Then I tried this:

typealias Result = Either<A, B<Self>>
return Result.with { … }

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!