You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
func scale(
of integer:Int,
by fraction:Double,
using operation:(Double,Double)->Double)->Int{returnoperation(integer, fraction)func operation(_ integer:Int, _ float:Double)->Int{letintegerInDouble=Double(integer)letresultInDouble=operation(integerInDouble, float)returnInt(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)
The text was updated successfully, but these errors were encountered:
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
In this contrived example:
I expect the local function
operation(_:_:)
to overload the parameteroperation(_:_:)
, 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:Environments:
The text was updated successfully, but these errors were encountered: