dynamicType from a property to an operator
- Proposal: SE-0096
- Author: Erica Sadun
- Review Manager: Chris Lattner
- Status: Implemented (Swift 3)
- Decision Notes: Rationale
- Bug: SR-2218
This proposal establishes
dynamicType as a named operator rather than a property.
Swift-evolution thread: RFC: didset and willset
dynamicType is a property. Because of that, it shows up as an "appropriate"
code completion for all values regardless of whether it makes sense to do so
or not. For example, Swift offers
Unlike most properties, it does not express a logical attribute of a specific type.
Instead, it can be applied to any expression. Since
dynamicType behaves more like a
sizeof), its user-facing calling syntax should follow suit.
Upon adoption of this proposal, Swift resyntaxes
dynamicType as an operator instead of a member.
This proposal puts forth
dynamicType(value) // returns the dynamicType of value
Once the Swift language has sufficient capabilities, the goal is to migrate this operation to the standard library. At this time, this operation cannot be written as a stdlib feature and it will be implemented as a compiler feature.
Impact on Existing Code
Adopting this proposal will break code and require migration support. The postfix property syntax must change to an operator call.
The core team may also consider
typeof(x) instead of
dynamicType(x) as the call is syntactically closer to
Note that this may introduce confusion. Unlike Swift, identically-named C++ and C# terms return static types.
Thank you, Nate Cook