scala-3-migration-guide icon indicating copy to clipboard operation
scala-3-migration-guide copied to clipboard

Import * now means wildcard

Open bishabosha opened this issue 3 years ago • 3 comments

There is probably a creative example where someone previously only wanted to import a * operation and now they import every operation, and importing everything now shadows some other definition.

class Operations {
  def *(i: Int, j: Int) = i * j
  def println(any: Any): Unit = ???
}

object Main extends App {
  val ops = new Operations()
  import ops.*
  println(*(2, 3))
}

Edit: on Scala 3 running Main will eval ??? in Operations.println, but Scala 2.13 will use Predef.println and print 6

bishabosha avatar May 18 '21 08:05 bishabosha

This is crazy! :smile:

adpi2 avatar May 25 '21 08:05 adpi2

The fact that this is crashing is a bug right? I would expect a compilation error on println(*(2, 3))?

julienrf avatar May 25 '21 09:05 julienrf

I think it is crashing because of the NotImplementedException in Operations.println

adpi2 avatar May 25 '21 09:05 adpi2