Skip to content

current package not preferred over imported package #5206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
olhotak opened this issue Oct 4, 2018 · 6 comments
Closed

current package not preferred over imported package #5206

olhotak opened this issue Oct 4, 2018 · 6 comments

Comments

@olhotak
Copy link
Contributor

olhotak commented Oct 4, 2018

I have three files:

package foo

object A {
  val x = 5
}
package foo.bar

object A {
  val x = "foo"
}
package foo
import foo.bar._

object B {
  val y: Int = A.x
}

They compile with Scala 2.12. With Dotty, I get:

-- [E007] Type Mismatch Error: /tmp/foo/B.scala:5:17 ---------------------------
5 |  val y: Int = A.x
  |               ^^^
  |               found:    String(foo.bar.A.x)
  |               required: Int
  |               
one error found

In object foo.B, Scala 2.12 prefers foo.A over foo.bar.A because foo.A is in the same package. But Dotty seems to prefer foo.bar.A over foo.A because foo.bar.A is being imported.

@milessabin
Copy link
Contributor

See also: scala/bug#2458.

I prefer Dotty's behaviour and I'd like to see it backported to Scala 2.

@allanrenucci
Copy link
Contributor

allanrenucci commented Oct 5, 2018

This is intended. If you compile with -language:Scala2, you get:

-- Migration Warning: Test.scala:16:17 -----------------------------
16 |    val y: Int = A.x
   |                 ^
   |               Name resolution will change.
   |                currently selected                     : foo.A.type
   |                in the future, without -language:Scala2: foo.bar.A'.type
   |               
   |               where:    A  is a object in package foo
   |                         A' is a object in package bar
one warning found

@milessabin
Copy link
Contributor

@allanrenucci s/Not/Note/ ?

@allanrenucci
Copy link
Contributor

Oops. I meant "Note". Closing since it is intended behaviour

@SethTisue
Copy link
Member

I prefer Dotty's behaviour and I'd like to see it backported to Scala 2.

you mean scala/scala#6589?

@milessabin
Copy link
Contributor

@SethTisue how did I miss that?! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants