Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No description defaults #80

Closed
oscbyspro opened this issue Sep 13, 2023 · 2 comments
Closed

No description defaults #80

oscbyspro opened this issue Sep 13, 2023 · 2 comments
Labels
subtraction huh? where did it go?
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Sep 13, 2023

I'm working on (#44) and noticed that description() calls the stdlib method in the context of NBKBinaryInteger. This is because the NBKBinaryInteger does not have default parameters, but the Swift.BinaryInteger convenience does.

// MARK: NBKBinaryInteger

func description(radix: Int, uppercase: Bool) -> String

// MARK: Swift.BinaryInteger

func description(radix: Int = 10, uppercase: Bool = false) -> String

// MARK: Numberick integers

func description(radix: Int = 10, uppercase: Bool = false) -> String

The solution is either removing the Swift.BinaryInteger defaults or adding this NBKBinaryInteger extension:

extension NBKBinaryInteger {

    // I thought this would cause infinite recursion, but apparently it doesn't.
    @inlinable public func description(radix: Int = 10, uppercase: Bool = false) -> String {
        self.description(radix: radix, uppercase: uppercase)
    }
}
@oscbyspro oscbyspro added this to the v0.12.0 milestone Sep 13, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 13, 2023

Hm. I'm leaning towards removing the defaults across the board, because I already have this extension:

extension String {
    
    @inlinable public init(_ source: some NBKBinaryInteger, radix: Int = 10, uppercase: Bool = false) {
        self = source.description(radix: radix, uppercase: uppercase)
    }
}

@oscbyspro oscbyspro added the subtraction huh? where did it go? label Sep 13, 2023
@oscbyspro oscbyspro changed the title Add or remove description(...) defaults No description(...) defaults Sep 13, 2023
oscbyspro added a commit that referenced this issue Sep 13, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 13, 2023

I also removed the default from NBKDoubleWidth.init(_:radix:), which was shadowed by init(_:).

@oscbyspro oscbyspro changed the title No description(...) defaults No description defaults Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subtraction huh? where did it go?
Projects
None yet
Development

No branches or pull requests

1 participant