Dotty: export doesn't work inside anonymous classes

Created on 8 Jan 2020  路  2Comments  路  Source: lampepfl/dotty

minimized code

class Bar {val glass : Int = 0}
class Foo(val bar : Bar) 
val f = new Foo(new Bar) {
  export bar._
}
val fGlass = f.glass //error: value glass is not a member of Foo

expectation

This code should compile. I see no reason why export shouldn't work in anonymous classes.

bug

Most helpful comment

This has nothing to do with exports. If you replace the export with val glass = bar.glass, it fails as well. See
https://contributors.scala-lang.org/t/better-type-inference-for-scala-send-us-your-problematic-cases/2410/73 for background.

I believe we should implement the Structural idea that @smarter proposed in that thread, though.

All 2 comments

This has nothing to do with exports. If you replace the export with val glass = bar.glass, it fails as well. See
https://contributors.scala-lang.org/t/better-type-inference-for-scala-send-us-your-problematic-cases/2410/73 for background.

I believe we should implement the Structural idea that @smarter proposed in that thread, though.

Fixed in #9201

class Bar {val glass : Int = 0}
class Foo(val bar : Bar) extends scala.reflect.Selectable
val f = new Foo(new Bar) {
  export bar._
}
val fGlass = f.glass

https://scastie.scala-lang.org/IrMU1eYaSBOW33nPbo2JOQ

Was this page helpful?
0 / 5 - 0 ratings