[swift-build-dev] Should Version be StringLiteralConvertible?

Ling Wang an00na at gmail.com
Mon Jan 4 16:55:29 CST 2016


Yes, as I said, I think there is no real consequence in current code. Just potential misusing danger in future. I suggest we use the help and protection of the type system as much as we can. That’s all.

> On Jan 4, 2016, at 4:49 PM, Max Howell <max.howell at apple.com> wrote:
> 
>> I guess there is not real consequence in the current code base. But it potentially lets us write crashing code like this without any help from the type system because we explicitly disabled the protection:
>> 
>> let version: Version = “hello”
>> 
>> By contrast, if Version is not StringLiteralConvertible, we must write code like this:
>> 
>> let version: Version = Version(“hello”)
>> 
>> where the type system will catch the error and force us to explicitly handle the potential `nil` result:
>> 
>> value of optional type 'Version?' not unwrapped; did you mean to use '!' or '?’?
> 
> 
> Well there’s two things:
> 
> 1. If done in a Package.swift it will fail to build. Which is good. We want it to fail to build if the version is invalid.
> 2. We don’t use this constructor in the Package Manager’s sources, for the reasons you specify.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-build-dev/attachments/20160104/6f2176b1/attachment.html>


More information about the swift-build-dev mailing list