Swift 2b4: Pointfree reference to generic initializer in generic context does not compile

Originator:rix.rob
Number:rdar://21928143 Date Originated:21-Jul-2015 05:30 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A165t)
Classification:Other Bug Reproducible:Always
 
Summary:
String.init works fine when the type it’s being applied to is well-known, but doesn’t seem to in a generic context.


Steps to Reproduce:
1. This code:
extension Array {
	func f() -> String {
		return ", ".join(lazy(self).map(String.init))
	}
}


Expected Results:
should compile

Actual Results:
but totally doesn’t:
rob@Resonance ~/Desktop> swiftc boom.swift
boom.swift:3:42: error: could not find an overload for 'String.init' that accepts the supplied arguments
                return ", ".join(lazy(self).map(String.init))
                                                ~~~~~~~^~~~

Regression:
It works fine if the type is known statically:
extension Array {
	func f() -> String {
		return ", ".join(lazy([1, 2, 3]).map(String.init))
	}
}

Notes:
N/A

Comments

Probably due to the overlapping generic init(_:) definitions

The following does compile:

extension Array where Element : SequenceType, Element.Generator.Element == Character {
    func f() -> String {
        return ", ".join(lazy(self).map(String.init))
    }
}

which calls this String.init overload:

init<S : SequenceType where S.Generator.Element == Character>(_ characters: S)

That suggests to me that swiftc is unable to figure out you'd want to unconditionally (?) call:

init<T>(_ instance: T)

in your Array extension.

By pyry.jahkola at July 22, 2015, 7:24 a.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!