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

Tim Vermeulen tvermeulen at me.com
Wed Jun 15 03:27:29 CDT 2016


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

None of them are very favorable. Allowing this proposed syntax will (in my opinion) lead to more readable code. In fact, inside the BinarySearchTree struct, BinarySearchTree is already an implicit typealias of BinarySearchTree<Key, Value>.

The only problem I foresee is that a generic typealias could cause confusion, so perhaps that shouldn’t be allowed here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160615/cba3b20c/attachment.html>


More information about the swift-evolution mailing list