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
extension (x: Int)
defadd(y: Int):Int= x + y
defnewFunction:Int=>Int=4.add
objectMainextendsApp:
println(newFunction(1))
Output
compiler error:
value add is not a member of IntAn extension method was tried, but could not be fully constructed:
{
def$anonfun(y: Int):Int= extension_add(4)(y)
closure($anonfun)
}
Expectation
5
Explanation
There are 3 other similar cases in which this works as expected, so the above example seems like the odd one out.
extension (x: Int)
defadd:Int=>Int= y => x + y
defnewFunction:Int=>Int=4.add
defadd:Int=>Int= y =>4+ y
defnewFunction:Int=>Int= add
defadd(x: Int):Int= x +4defnewFunction:Int=>Int= add
The first two are similar in that both add functions have a return type of Int => Int.
The interesting bit is that the third one works as expected (converting a function defined with (x: Int): Int into Int => Int, but this same conversion doesn't take place inside the context of an extension.
I don't know how extensions are actually implemented, and this might be expected behavior, which is why I didn't categorize this as a bug, just figured I'd mention since it seemed odd to me.
The text was updated successfully, but these errors were encountered:
Tylerwbrown
changed the title
Inconsistency between extension methods and normal methods
Inconsistency with partial application/currying between extension methods and functions
Aug 6, 2020
Minimized example
Output
compiler error:
Expectation
5
Explanation
There are 3 other similar cases in which this works as expected, so the above example seems like the odd one out.
The first two are similar in that both
add
functions have a return type ofInt => Int
.The interesting bit is that the third one works as expected (converting a function defined with
(x: Int): Int
intoInt => Int
, but this same conversion doesn't take place inside the context of an extension.I don't know how extensions are actually implemented, and this might be expected behavior, which is why I didn't categorize this as a bug, just figured I'd mention since it seemed odd to me.
The text was updated successfully, but these errors were encountered: