How to call conflict package level function

Could someone help me solve the TODO line in the code below?

fun printLine() {
  println("Package-level function outside main")
}

fun main() {
  fun printLine() {
    println("Top-level function inside main")
  }

  class A {
    fun printLine() {
      println("Member function A")
    }

    inner class B {
      fun printLine() {
        println("Member function B")
      }

      fun invokePrintLine() {
        // TODO: how to call printLine to print "Package-level function outside main"
        printLine() // Top-level function inside main
        this@A.printLine() // Member function A (label)
        this.printLine() // Member function B (closest)
      }
    }
  }

  A().B().invokePrintLine()
}
1 Like

Give it a package name, then do package.name.printLine()

Like this:

package test.hello
fun printLine() {
  println("Package-level function outside main")
}

fun main() {
  fun printLine() {
    println("Top-level function inside main")
  }

  class A {
    fun printLine() {
      println("Member function A")
    }

    inner class B {
      fun printLine() {
        println("Member function B")
      }

      fun invokePrintLine() {
        test.hello.printLine()
        printLine() // Top-level function inside main
        this@A.printLine() // Member function A (label)
        this.printLine() // Member function B (closest)
      }
    }
  }

  A().B().invokePrintLine()
}
1 Like

Nice to know that way. So it’s not possible to access the default package function, hm.
Actually, here is a ticket for this feature and JB doesn’t plan to support it.

1 Like