[swift-evolution] Allow a typealias to be named after the corresponding type

Haravikk swift-evolution at haravikk.me
Wed Jun 15 04:50:58 CDT 2016


> On 15 Jun 2016, at 09:35, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> public struct BinarySearchTree<Key: Comparable, Value> {
>>    typealias Node = Node<Key, Value>
>>    var root: Node?
>> }
>> 
>> private class Node<Key: Comparable, Value> { }
>> 
>> This code currently doesn’t compile because the Node typealias circularly references itself. I’d like this syntax to just work, because this are the alternatives:
>> - rename the typealias to something like `TheNode`
>> - rename the Node class
>> - don’t use a typealias at all
> 
> - fully qualify the class name with the name of the module:
> 
> 	typealias Node = DataStructureKit.Node<Key, Value>

This. Though I do sympathise with the issue, as it’s kind of strange that a circular reference is assumed rather than searching for something else in scope, as this differs from how things like variable shadowing behave.

That said, I think fully qualifying the type is the right solution in this case, but I wonder if we might consider a fixit capable of suggesting possible matching types?


More information about the swift-evolution mailing list