I either don't understand or can't reproduce the issue. This code:
> class Box {
> let value: Int
>
> init(value: Int) {
> self.value = value
> }
> }
>
> let test: UInt32 = 4
> let box = Box(value: test)
does not compile ("foo.swift:10:22: error: cannot convert value of type
'UInt32' to expected argument type 'Int'").
Félix
> Le 6 janv. 2016 à 13:17:03, James Campbell <[email protected]> a écrit :
>
> protocol Box: CustomStringConvertible, CustomDebugStringConvertible {
>
>
> typealias FloatLiteralType = Double
>
> typealias IntegerLiteralType = Int
>
> typealias BoxType = Any
>
>
> var value: BoxType { get set }
>
>
> init()
>
> init(_ value: BoxType)
>
> }
>
> extension Box where Self.BoxType == Double {
>
>
> init(_ value: Double) {
>
>
> self.init()
>
> self.value = value
>
> }
>
>
> init(_ value: Int) {
>
> self.init()
>
> self.value = Double(value)
>
> }
>
>
> init(_ value: UInt32) {
>
> self.init()
>
> self.value = Double(value)
>
> }
>
> }
>
>
>
>
>
> Without that last method, Swift tries to give the UInt32 to the Int version
> of the method which isn't safe in my eyes and I would have expected a
> compiler error.
>
>
> On Wed, Jan 6, 2016 at 6:14 PM, Félix Cloutier <[email protected]
> <mailto:[email protected]>> wrote:
> I don't understand. Can you show a code example?
>
> Félix
>
>> Le 6 janv. 2016 à 13:02:43, James Campbell via swift-evolution
>> <[email protected] <mailto:[email protected]>> a écrit :
>>
>> I have a overloaded method for a protocol that takes an Int or double.
>>
>> I have an issue with swift calling the Int version when passing in a UInt32
>> . Ideally I would prefer the compiler to detect I am about to do something
>> which will cause an overflow and throw an error.
>>
>> I would then have to explicitly add a overloaded UInt32 method or explicitly
>> convert it to Int like so "Int(uintVariable)".
>>
>> --
>> Wizard
>> [email protected] <mailto:[email protected]>
>> +44 7523 279 698 <tel:%2B44%207523%20279%20698>
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
>
>
>
> --
> Wizard
> [email protected] <mailto:[email protected]>
> +44 7523 279 698
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution