oscbyspro / Numberick

An arithmagick overhaul in Swift
Apache License 2.0
15 stars 3 forks source link

No vanilla protocol extensions (there's one) #96

Closed oscbyspro closed 1 year ago

oscbyspro commented 1 year ago

I have this one extension on Swift.BinaryInteger (because it would be recursive elsewhere):

extension Swift.BinaryInteger {
    @inlinable public func description(radix: Int, uppercase: Bool) -> String {
        String(self, radix: radix, uppercase: uppercase)
    }
}

I think it would be more elegant if I did not touch the vanilla protocols. Here's an alternative:

extension NBKCoreInteger {
    @inlinable public func description(radix: Int, uppercase: Bool) -> String {
        // without infinite recursion, yay!
        // self as some Swift.BinaryInteger is invalid syntax :(
        String(NBK.someSwiftBinaryInteger(self), radix: radix, uppercase: uppercase)
    }
}
oscbyspro commented 1 year ago

Changed the title because I'm keeping this method:

extension Swift.StaticBigInt {
    @inlinable public init(_ other: NBKStaticBigInt) {
        self = other.base
    }
}
oscbyspro commented 1 year ago

That moment when a type can be inferred in Swift 5.8 but not in Swift 5.7.

// Swift 5.7: 🛑 [...] has no return statements [...] from which to infer an underlying type
func someSwiftFixedWidthIntegerType(
_ x: (some Swift.FixedWidthInteger).Type
) -> (some Swift.FixedWidthInteger).Type { x }