[swift-dev] Delaying the enforcement of ".self" out of Swift 3?

Douglas Gregor dgregor at apple.com
Thu Jun 2 15:21:02 CDT 2016


Hi all,

While working on some unrelated refactoring, I stumbled across a minor fix that would make use properly enforce “.self” when we want to get the metatype of a named type. For example, the Swift compiler currently (incorrectly) allows

	sizeof(UInt)

which should be

	sizeof(UInt.self)

The fix for this is actually pretty simple (patch attached), but the question is… do we want to fix the problem, if we think that we’ll get SE-0090 that makes “.self” go away?

	https://github.com/apple/swift-evolution/blob/master/proposals/0090-remove-dot-self.md

On the one hand, I want to fix the problem:

	* This came out of a desire to make the AST more sane. Essentially, the folding of expressions into TypeExprs—which will go away entirely if/when SE-0090 is implemented—is pulling in the parentheses describing call arguments. Without the fix, we still have weird AST.
	* SE-0090 is labeled as “deferred out of Swift 3”, so having the compiler not implement the stated language for an entire release cycle seems really unfortunate.

OTOH, I don’t want to jerk people’s code around, forcing them to add “.self” now only to remove it a year from now (or whenever).

Thoughts?

	- Doug

-------------- next part --------------
A non-text attachment was scrubbed...
Name: enforce-metatype-self.patch
Type: application/octet-stream
Size: 6032 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160602/2dae010a/attachment.obj>


More information about the swift-dev mailing list