[swift-evolution] [Draft] Fix ExpressibleByStringInterpolation

Brent Royal-Gordon brent at architechies.com
Thu Mar 9 20:18:06 CST 2017


...is the title of a proposal I wrote today. The full proposal is available at:

	<https://github.com/brentdax/swift-evolution/blob/bdce720e9d0f7015f8741716035198c41fa117a0/proposals/NNNN-fix-expressible-by-string-interpolation.md>

But the tl;dr is that, if you write this:

	"Hello, \(name)!"

Instead of generating this:

	.init(stringInterpolation:
		.init(stringInterpolationSegment: .init(stringLiteral: "Hello, ")),
		.init(stringInterpolationSegment: name),
		.init(stringInterpolationSegment: .init(stringLiteral: "!"))
	)

We should generate this:

	.init(stringInterpolation:
		.init(stringLiteral: "Hello, "),
		.init(stringInterpolationSegment: name),
		.init(stringLiteral: "!")
	)

I actually have an implementation of it, available here:

	<https://github.com/apple/swift/compare/master...brentdax:new-interpolation>

But I'm literally messing with the constraint generator the very first time I modify the compiler, so I'm assuming it'll need some serious code review before it actually gets pulled in. (All the regular tests *do* at least pass.)

Despite the word "fix" in the title, this really only does half the job; I think we also need to tackle string formatting, at least by adding a mechanism, if not by settling on exact APIs. The proposal includes a sketch of my thoughts about that as well.

Comments extremely welcome.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list