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
➜ snips scalac gottenclass.scala
-- [E049] ReferenceError: gottenclass.scala:8:8-----------------------------------------------------------------------8|deff= getClass
|^^^^^^^^|Reference to getClass is ambiguous,
| it is both imported by importX._| and imported subsequently by importY._
longer explanation available when compiling with`-explain`1 error found
Expectation
The Scala 2 fix was that "root imports" do not import universal methods. That was to avoid a bug where secondary constructors used getClass and got Predef.getClass.
In this case, getClass would be expected to pick up the class of the enclosing package object, as happens with this.getClass.
Without the ambiguity and without this, getClass is resolved by some arbitrary wildcard import, which is obviously unintended. (That is, more unintended than importing from Predef.)
More importantly, that example shows a usage of getClass where class loading might be important (that is, getResource might be using an unexpected class path).
Related to #7713 except here the competing import is not a root import.
The text was updated successfully, but these errors were encountered:
Compiler version
3.1.1
Minimized code
Output
Expectation
The Scala 2 fix was that "root imports" do not import universal methods. That was to avoid a bug where secondary constructors used
getClass
and gotPredef.getClass
.In this case,
getClass
would be expected to pick up the class of the enclosing package object, as happens withthis.getClass
.Without the ambiguity and without
this
,getClass
is resolved by some arbitrary wildcard import, which is obviously unintended. (That is, more unintended than importing fromPredef
.)Real world example at https://github.com/lampepfl/dotty/blob/3.1.2/compiler/test/dotty/tools/utils.scala#L16 is one wildcard import away from ambiguity.
More importantly, that example shows a usage of
getClass
where class loading might be important (that is,getResource
might be using an unexpected class path).Related to #7713 except here the competing import is not a root import.
The text was updated successfully, but these errors were encountered: