Problem calling overloaded functions with function parameters


#1

Hi,

The following fail to compile with Overload resolution ambiguity: internal final fun Foo.repeat(n : jet.Int, block : () -> Unit) : Unit defined in root package internal final fun Foo.repeat(n : jet.Int, block : (jet.Int) -> Unit) : Unit defined in root package

class Foo fun Foo.repeat(n : Int, block: ()->Unit) {      for (i in 1 .. n)           block() } fun Foo.repeat(n : Int, block: (Int)->Unit) {      for(i in (1 .. n))           block(i) }

fun main(args : Array<String>) {
     Foo().repeat(3){ println(“test”) }          // case 1
     Foo().repeat(3){ i -> println(“test $i”) }  // case 2
}


What’s is interesting is that if I comment out just the “case 1” line, the program will run “case 2” without problem.

So the question I have is overloaded functions that has function as parameter officially supported? If yes, this would be a bug then?

Thanks,
Zemian


#2

This is a bug. A workaround is to explicitly specify parameters in function literals.

Please, report to the tracker. Thanks


#3

http://youtrack.jetbrains.com/issue/KT-3212