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

Ling Wang an00na at gmail.com
Mon Jan 4 16:43:03 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 '?'?

> On Jan 4, 2016, at 1:22 PM, Max Howell <max.howell at apple.com> wrote:
> Can you provide a use case that demonstrates the danger?
> I can only imagine situations where the Package.swift is invalid and thus `swift build` simply errors out.  No data is lost, no work is lost. Just time.
>> On Dec 30, 2015, at 1:16 PM, Ling Wang via swift-build-dev <swift-build-dev at swift.org> wrote:
>> Because Version.init?(_ characters:) is really failable this code is very dangerous:
>> extension Version: StringLiteralConvertible {
>>   public init(stringLiteral value: String) {
>>       self.init(value.characters)!
>>   }
>> Is the convenience worth it?
>> _______________________________________________
>> swift-build-dev mailing list
>> swift-build-dev at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-build-dev

More information about the swift-build-dev mailing list