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

Local function that shares the same name with a parameter of its parent function but differs by type signatures shadows the parameter instead of overloading it #59719

Open
WowbaggersLiquidLunch opened this issue Jun 27, 2022 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. parser Area → compiler: The legacy C++ parser

Comments

@WowbaggersLiquidLunch
Copy link
Contributor

WowbaggersLiquidLunch commented Jun 27, 2022

In this contrived example:

func scale(
    of integer: Int,
    by fraction: Double,
    using operation: (Double, Double) -> Double
) -> Int {
    return operation(integer, fraction)
    func operation(_ integer: Int, _ float: Double) -> Int {
        let integerInDouble = Double(integer)
        let resultInDouble = operation(integerInDouble, float)
        return Int(resultInDouble)
    }
}

I expect the local function operation(_:_:) to overload the parameter operation(_:_:), because they're of different types ((Int, Double) -> Double and (Double, Double) -> Double). But what actually happens is that the local function shadows the parameter, and results in this error:

9:34: error: cannot convert value of type 'Double' to expected argument type 'Int'
               let resultInDouble = operation(integerInDouble, float)

Environments:

@WowbaggersLiquidLunch WowbaggersLiquidLunch added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. parser Area → compiler: The legacy C++ parser labels Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

1 participant