forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#5804 from jvican/stub-errors-2.11.8
Backport 2.11.9: Improve stub error messages (SCP-009 proposal)
- Loading branch information
Showing
31 changed files
with
465 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/partest-extras/scala/tools/partest/StubErrorMessageTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package scala.tools.partest | ||
|
||
trait StubErrorMessageTest extends StoreReporterDirectTest { | ||
// Stub to feed to partest, unused | ||
def code = throw new Error("Use `userCode` instead of `code`.") | ||
|
||
val classpath = List(sys.props("partest.lib"), testOutput.path) | ||
.mkString(sys.props("path.separator")) | ||
|
||
def compileCode(codes: String*) = { | ||
val global = newCompiler("-cp", classpath, "-d", testOutput.path) | ||
val sourceFiles = newSources(codes: _*) | ||
withRun(global)(_ compileSources sourceFiles) | ||
} | ||
|
||
def removeClasses(inPackage: String, classNames: Seq[String]): Unit = { | ||
val pkg = new File(testOutput.path, inPackage) | ||
classNames.foreach { className => | ||
val classFile = new File(pkg, s"$className.class") | ||
assert(classFile.exists) | ||
assert(classFile.delete()) | ||
} | ||
} | ||
|
||
def removeFromClasspath(): Unit | ||
def codeA: String | ||
def codeB: String | ||
def userCode: String | ||
def extraUserCode: String = "" | ||
|
||
def show(): Unit = { | ||
compileCode(codeA) | ||
assert(filteredInfos.isEmpty, filteredInfos) | ||
|
||
compileCode(codeB) | ||
assert(filteredInfos.isEmpty, filteredInfos) | ||
removeFromClasspath() | ||
|
||
if (extraUserCode == "") compileCode(userCode) | ||
else compileCode(userCode, extraUserCode) | ||
import scala.reflect.internal.util.Position | ||
filteredInfos.map { report => | ||
print(if (report.severity == storeReporter.ERROR) "error: " else "") | ||
println(Position.formatMessage(report.pos, report.msg, true)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
error: missing or invalid dependency detected while loading class file 'Imports.class'. | ||
Could not access type Wrapper in class scala.tools.nsc.interpreter.IMain.Request, | ||
because it (or its dependencies) are missing. Check your build definition for | ||
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) | ||
A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain.Request. | ||
error: missing or invalid dependency detected while loading class file 'Imports.class'. | ||
Could not access type Request in class scala.tools.nsc.interpreter.IMain, | ||
because it (or its dependencies) are missing. Check your build definition for | ||
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) | ||
A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain. | ||
two errors found | ||
t5148.scala:4: error: Symbol 'type <none>.Request.Wrapper' is missing from the classpath. | ||
This symbol is required by 'value scala.tools.nsc.interpreter.Imports.wrapper'. | ||
Make sure that type Wrapper is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. | ||
A full rebuild may help if 'Imports.class' was compiled against an incompatible version of <none>.Request. | ||
class IMain extends Imports | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: newSource1.scala:4: Symbol 'type stuberrors.A' is missing from the classpath. | ||
This symbol is required by 'class stuberrors.B'. | ||
Make sure that type A is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. | ||
A full rebuild may help if 'B.class' was compiled against an incompatible version of stuberrors. | ||
new B | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
object Test extends scala.tools.partest.StubErrorMessageTest { | ||
def codeA = """ | ||
package stuberrors | ||
class A | ||
""" | ||
|
||
def codeB = """ | ||
package stuberrors | ||
class B extends A | ||
""" | ||
|
||
def userCode = """ | ||
package stuberrors | ||
class C { | ||
new B | ||
} | ||
""" | ||
|
||
def removeFromClasspath(): Unit = { | ||
removeClasses("stuberrors", List("A")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: newSource1.scala:9: Symbol 'type stuberrors.A' is missing from the classpath. | ||
This symbol is required by 'class stuberrors.B.BB'. | ||
Make sure that type A is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. | ||
A full rebuild may help if 'B.class' was compiled against an incompatible version of stuberrors. | ||
new b.BB | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
object Test extends scala.tools.partest.StubErrorMessageTest { | ||
def codeA = """ | ||
package stuberrors | ||
class A | ||
""" | ||
|
||
def codeB = """ | ||
package stuberrors | ||
class B { | ||
def foo: String = ??? | ||
// unused and should fail, but not loaded | ||
def unsafeFoo: A = ??? | ||
// used, B.info -> BB.info -> unpickling A -> stub error | ||
class BB extends A | ||
} | ||
""" | ||
|
||
def userCode = """ | ||
package stuberrors | ||
class C { | ||
def aloha = { | ||
val b = new B | ||
val d = new extra.D | ||
d.foo | ||
println(b.foo) | ||
new b.BB | ||
} | ||
} | ||
""" | ||
|
||
override def extraUserCode = """ | ||
package extra | ||
class D { | ||
def foo = "Hello, World" | ||
} | ||
""".stripMargin | ||
|
||
def removeFromClasspath(): Unit = { | ||
removeClasses("stuberrors", List("A")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: newSource1.scala:4: Symbol 'type stuberrors.A' is missing from the classpath. | ||
This symbol is required by 'type stuberrors.B.D'. | ||
Make sure that type A is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. | ||
A full rebuild may help if 'B.class' was compiled against an incompatible version of stuberrors. | ||
println(new B) | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
object Test extends scala.tools.partest.StubErrorMessageTest { | ||
def codeA = """ | ||
package stuberrors | ||
class A | ||
""" | ||
|
||
def codeB = """ | ||
package stuberrors | ||
class B[D <: A] | ||
""" | ||
|
||
def userCode = """ | ||
package stuberrors | ||
object C extends App { | ||
println(new B) | ||
} | ||
""" | ||
|
||
def removeFromClasspath(): Unit = { | ||
removeClasses("stuberrors", List("A")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: newSource1.scala:13: Symbol 'type stuberrors.A' is missing from the classpath. | ||
This symbol is required by 'method stuberrors.B.foo'. | ||
Make sure that type A is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. | ||
A full rebuild may help if 'B.class' was compiled against an incompatible version of stuberrors. | ||
b.foo | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
object Test extends scala.tools.partest.StubErrorMessageTest { | ||
def codeA = """ | ||
package stuberrors | ||
class A | ||
class AA | ||
""" | ||
|
||
def codeB = """ | ||
package stuberrors | ||
abstract class B { | ||
def bar: String = ??? | ||
def foo: A = new A | ||
def baz: String = ??? | ||
} | ||
""" | ||
|
||
def userCode = """ | ||
package stuberrors | ||
abstract class C extends App { | ||
val b = new B {} | ||
// Use other symbols in the meanwhile | ||
val aa = new AA | ||
val dummy = 1 | ||
println(dummy) | ||
// Should blow up | ||
b.foo | ||
} | ||
""" | ||
|
||
def removeFromClasspath(): Unit = { | ||
removeClasses("stuberrors", List("A")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: newSource1.scala:13: Symbol 'type stuberrors.A' is missing from the classpath. | ||
This symbol is required by 'method stuberrors.B.foo'. | ||
Make sure that type A is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. | ||
A full rebuild may help if 'B.class' was compiled against an incompatible version of stuberrors. | ||
b.foo | ||
^ |
Oops, something went wrong.