[Swift] Return type of init not correctly inferred to be Self

Originator:alex
Number:rdar://23671426 Date Originated:26-Nov-2015 04:12 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1.1 (7B1005) and 7.2 beta (7C62b)
Classification:Other Bug Reproducible:Always
 
Summary:
When having a protocol with a required initialiser and this required initialiser is used as the return value of static method in a protocol extension with return type Self the compiler fails with the following error message although it is obvious that the return type of Self is correct

Method 'xyz()' in non-final class 'ABC' must return `Self` to conform to protocol 'DEF'

Steps to Reproduce:
Try to compile the attached sample project

Expected Results:
The code should compile fine since it is obvious that self.init() returns a value of type Self

Actual Results:
The compiler fails with the following error message: 

Method 'construct()' in non-final class 'A' must return `Self` to conform to protocol 'P'

Version:
Xcode 7.1.1 (7B1005) and 7.2 beta (7C62b)

OS X 10.11.1 (15B42)

Notes:
Providing a static method that basically returns the value of a constructor is useful when overloading the static method for multiple return types

Configuration:
The code compiles fine if A is final

Attachments:
'DemoProject.zip' was successfully uploaded.

The demo project contains the following code:

public protocol P {
	init()
	
	static func construct() -> Self
}

extension P {
	public static func construct() -> Self {
		return self.init()
	}
}

class A: P {
	required init() {
	}
}

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!