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

Max Howell max.howell at apple.com
Mon Jan 4 16:49:56 CST 2016

> 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.

More information about the swift-build-dev mailing list