scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

More informative error message when classes can't be found on the classpath. #4492

Closed scabug closed 10 years ago

scabug commented 13 years ago

=== What steps will reproduce the problem (please be specific and use wikiformatting)? === Consider these three simple Scala source files:

File projectA/org/example/a/A.scala:

package org.example.a

class A

File projectB/org/example/b/B.scala:

package org.example.b

import org.example.a.A

class B {
  val a = new A()
}

File projectC/org/example/c/C.scala:

package org.example.c

import org.example.b.B

class C {
  val b = new B()
  b.a
}

Now, we compile the first two separately without problems:

$$ scalac -d bin/projectA/ projectA/src/org/example/a/
$$ scalac -d bin/projectB/ -cp bin/projectA/ projectB/src/

Compiling the 3rd requires both projectA and projectB on the classpath. Leaving out projectA causes an expected error, but the error message is not as helpful as it could be:

$$ scalac -d bin/projectC/ -cp bin/projectB/ projectC/src/org/example/c/C.scala
error: class file needed by B is missing.
reference value a of package org.example refers to nonexisting symbol.
one error found

If we reimplement class C in Java:

package org.example.c;

import org.example.b.B;

class C {
  public final B b;

  public C() {
    b = new B();
    b.a();
  }
}

and then compile using the Java compiler we get:

$$ javac -d bin/projectC/ -cp bin/projectB/:scala-library.jar projectC/src/org/example/c/C.java
projectC/src/org/example/c/C.java:10: cannot access org.example.a.A
class file for org.example.a.A not found
    b.a();
       ^
1 error

This error tells us exactly what is wrong.

The source and a build script is attached.

=== Additional information === Doing the same in Eclipse leads to an even better error message (actually two messages):

This issue was originally (incorrectly) raised as part of another ticket on the Scala IDE bug tracking system:

=== What versions of the following are you using? ===

scabug commented 13 years ago

Imported From: https://issues.scala-lang.org/browse/SI-4492?orig=1 Reporter: Martin Gamwell Dawids (mgd) See #4876 Attachments:

scabug commented 13 years ago

Martin Gamwell Dawids (mgd) said: Reproduction scenario

scabug commented 11 years ago

@adriaanm said: Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw

scabug commented 11 years ago

@adriaanm said: Unassigning and rescheduling to M6 as previous deadline was missed.

scabug commented 10 years ago

@adriaanm said: Marking this as critical because the modularization may cause more of these. We should try to detect when someone needs to add scala-xml and be helpful in suggestion a dependency on scala-library-all, or a more fine-grained one.

scabug commented 10 years ago

@adriaanm said: Tweaked error message and a position: https://github.com/scala/scala/pull/3631

scabug commented 10 years ago

@adriaanm said: It'll be hard to reach parity with javac, but the above PR gets us close. The evaluation order during symbol loading is structured differently; thus, we complain about the package org.example.a before we get to the type org.example.a.A, making the error message a little less focussed.