Weird behaviour when using generic functions in protocols and opaque types

Yup, so the feature you're relying on is called associated type inference, which is pretty convenient when it works. However:

Our current system for associated type inference and associated type defaults is buggy and complicated.

A proposal to remove the feature outright was rejected, and other attempts to rework the feature haven't really panned out.

Here, you're encountering the issue that associated type inference can't infer typealias W = some Widget [result of widgetFor(keypath:)] based on your implementation of a generic function requirement. Meanwhile, you can't actually spell out result of widgetFor(keypath:) explicitly as a typealias. This is indeed a limitation of Swift today.

5 Likes