scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.85k stars 1.06k forks source link

package object member "type X" not found if "object X" exists in the same package #2200

Closed olafurpg closed 7 years ago

olafurpg commented 7 years ago

I found one example with type aliases and higher kinded types where scalac reports no type errors while dotc reports E006 Unbound Identifier Error https://github.com/lampepfl/dotty/commit/cf26eeb502b958a4f7b45530acfe74235f0dba0d#commitcomment-21672034

I bumped into this error while trying to compile https://github.com/johnynek/paiges with Dotty. The commands I ran were


$ scalac -version
Scala compiler version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.
$ scalac tests/pos/packageobjecttypealias/*.scala
$ ./bin/dotc tests/pos/packageobjecttypealias/*.scala 
smarter commented 7 years ago
  1. E006 Unbound Identifier Error cf26eeb#commitcomment-21672034

The problem seems to be that the stuff in the package object is not found, I've seen that happen before. The reason is that we cache the package object denotation, but sometimes we cache it before the package object has been entered into scope, so the cache is wrong and never invalidated. I don't know if there's a systematic solution to this, maybe simply dropping the cache assuming it doesn't have a big impact on performance? /cc @odersky

  1. E007 Type mismatch eae920a#commitcomment-21672052

That's a good one! No clue what's going on but it shouldn't be too hard to debug.

@olafurpg Since these are two separate issues, would you mine splitting this issue into two?

olafurpg commented 7 years ago

Since these are two separate issues, would you mine splitting this issue into two?

@smarter Done, see #2201. I removed the reference to the second error of the description in this issue.

odersky commented 7 years ago

It's not just a caching problem. The problem is that the first type found is the class type that comes with the DocString object, but that one does not really exist. But by then we don't look in the package object anymore. It's tricky because at the point where we do look into the package object we are not allowed to ask whether the companion class really exists, as that would force too much.

smarter commented 7 years ago

@odersky Ah, I see! So it's not the issue I thought it was.

odersky commented 7 years ago

Fixed by #2205

olafurpg commented 7 years ago

I confirm that I'm unable to reproduce the error after #2205.