generics - What does the "_" type mean in swift error messages? -
occasionally when using generics, error message refers "_" parameter. doesn't appear documented. mean?
as example, error:
cannot convert value of type 'jawdroppingfeat<superhero>' closure result type 'jawdroppingfeat<_>' when try compile:
protocol superherotype { typealias superpower } struct jawdroppingfeat<superhero: superherotype superhero: arbitrary, superhero.superpower: arbitrary>: arbitrary { let subject: superhero let superpowerused: superhero.superpower static var arbitrary: gen<jawdroppingfeat<superhero>> { { return gen.zip(superhero.arbitrary, superhero.superpower.arbitrary) .map{ (x: superhero, y: superhero.superpower) in jawdroppingfeat(subject: x, superpowerused: y) } } } } the gen , arbitrary types swiftcheck , relevant declarations are:
public struct gen<a> { public static func zip<a, b>(gen1: swiftcheck.gen<a>, _ gen2: swiftcheck.gen<b>) -> swiftcheck.gen<(a, b)> public func map<b>(f: -> b) -> swiftcheck.gen<b> } public protocol arbitrary { public static var arbitrary: swiftcheck.gen<self> { } } i assume <_> swift failing infer type parameter rather image of chris lattner wincing @ me. have more precise (and documented) meaning?
edit
my best current theory when swift fails infer type parameter, instead of failing immediately, assigns null (_) type, results in actual compile error downstream @ point incompatible type (in case, parameters .map) passed.
it means have incomplete type information in return value of parameter.
in case .map function returning generic jawdroppingfeat did not specify embedded type.
i assume meant write
jawdroppingfeat<superhero>(subject: x, superpowerused: y)
Comments
Post a Comment