Skip to content
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

Confusing error message involving stabilized term #11808

Open
ignatich opened this issue Nov 22, 2019 · 3 comments
Open

Confusing error message involving stabilized term #11808

ignatich opened this issue Nov 22, 2019 · 3 comments

Comments

@ignatich
Copy link

@ignatich ignatich commented Nov 22, 2019

class Outer {
  class Inner() {}
  def getInner = new Inner()
  def useInner(inner: Inner): Unit = {
  }
}
class Container {
  var outer: Outer = _
  outer = new Outer
}
class UseContainer(c: Container) {
  import c.outer
  outer.useInner(outer.getInner)
}

in Scala 2.13.1 this code does not compile with the following error:

type mismatch;
[error]  found   : Outer#Inner
[error]  required: stabilizer$1.Inner
[error]   outer.useInner(outer.getInner)
[error]                        ^
[error] one error found

Using c.outer directly, instead of importing it compiles ok (as well as replacing var with a val, etc).
I expected that importing a var from some instance should be equivalent to using it directly, is that wrong?

@som-snytt

This comment has been minimized.

Copy link

@som-snytt som-snytt commented Nov 22, 2019

To clarify, only version 3 compiles:

$ cat t11808.scala
class Outer {
  class Inner() {}
  def getInner = new Inner()
  def useInner(inner: Inner): Unit = {
  }
}
class Container {
  var outer: Outer = new Outer
}
class UseContainer3(c: Container) {
  val stable = c.outer
  stable.useInner(stable.getInner)
}
class UseContainer2(c: Container) {
  c.outer.useInner(c.outer.getInner)
}
class UseContainer(c: Container) {
  import c.outer
  outer.useInner(outer.getInner)
}

The other examples compile the same:

$ scalac t11808.scala
t11808.scala:15: error: type mismatch;
 found   : Outer#Inner
 required: stabilizer$1.Inner
  c.outer.useInner(c.outer.getInner)
                           ^
t11808.scala:19: error: type mismatch;
 found   : Outer#Inner
 required: stabilizer$1.Inner
  outer.useInner(outer.getInner)
                       ^
two errors found

The message could be friendlier. Similarly for implicit parameter:

error: could not find implicit value for parameter x: stabilizer$1.Inner
@ignatich

This comment has been minimized.

Copy link
Author

@ignatich ignatich commented Nov 22, 2019

Yep, looks like I made a mistake while checking version w/o import, and this is not related to imports at all.

@som-snytt som-snytt changed the title Confusing type error when using inner class, while outer class is imported from a var Confusing error message involving stabilized term, should be "stabiliser" Nov 23, 2019
@som-snytt som-snytt changed the title Confusing error message involving stabilized term, should be "stabiliser" Confusing error message involving stabilized term Nov 25, 2019
@som-snytt

This comment has been minimized.

Copy link

@som-snytt som-snytt commented Nov 25, 2019

Edited out my s/z joke. It was a case of the wag dogging the title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.