Problem calling overloaded functions with function parameters

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

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

Please, report to the tracker. Thanks

1 Like

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

1 Like