summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala25
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala36
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala8
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala6
-rw-r--r--test/files/neg/abstract-explaintypes.check11
-rw-r--r--test/files/neg/abstract-explaintypes.flags1
-rw-r--r--test/files/neg/abstract-explaintypes.scala11
-rw-r--r--test/files/pos/t6123-explaintypes-implicits.flags1
-rw-r--r--test/files/pos/t6123-explaintypes-implicits.scala13
-rw-r--r--test/files/pos/t6123-explaintypes-macros.flags1
-rw-r--r--test/files/pos/t6123-explaintypes-macros.scala7
-rwxr-xr-xtest/files/run/t5717.scala21
12 files changed, 107 insertions, 34 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala b/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala
index c1cd3204e0..66aed14d1c 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala
@@ -6,12 +6,15 @@
package scala.tools.nsc
package backend.jvm
-import java.io.{ DataOutputStream, FileOutputStream, OutputStream, File => JFile }
+import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream, File => JFile }
import scala.tools.nsc.io._
import scala.tools.nsc.util.ScalaClassLoader
import java.util.jar.Attributes.Name
import scala.language.postfixOps
+/** Can't output a file due to the state of the file system. */
+class FileConflictException(msg: String, val file: AbstractFile) extends IOException(msg)
+
/** For the last mile: turning generated bytecode in memory into
* something you can use. Has implementations for writing to class
* files, jars, and disassembled/javap output.
@@ -20,16 +23,20 @@ trait BytecodeWriters {
val global: Global
import global._
- private def outputDirectory(sym: Symbol): AbstractFile = (
- settings.outputDirs.outputDirFor(enteringFlatten(sym.sourceFile))
- )
- private def getFile(base: AbstractFile, /*cls.getName()*/ clsName: String, suffix: String): AbstractFile = {
+ private def outputDirectory(sym: Symbol): AbstractFile =
+ settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile)
+
+ /**
+ * @param clsName cls.getName
+ */
+ private def getFile(base: AbstractFile, clsName: String, suffix: String): AbstractFile = {
+ def ensureDirectory(dir: AbstractFile): AbstractFile =
+ if (dir.isDirectory) dir
+ else throw new FileConflictException(s"${base.path}/$clsName$suffix: ${dir.path} is not a directory", dir)
var dir = base
val pathParts = clsName.split("[./]").toList
- for (part <- pathParts.init) {
- dir = dir.subdirectoryNamed(part)
- }
- dir.fileNamed(pathParts.last + suffix)
+ for (part <- pathParts.init) dir = ensureDirectory(dir) subdirectoryNamed part
+ ensureDirectory(dir) fileNamed pathParts.last + suffix
}
private def getFile(sym: Symbol, clsName: String, suffix: String): AbstractFile =
getFile(outputDirectory(sym), clsName, suffix)
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index 8d9c4290ce..1cc46293ae 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -105,29 +105,30 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
"Such classes will overwrite one another on case-insensitive filesystems.")
}
- debuglog("Created new bytecode generator for " + classes.size + " classes.")
+ debuglog(s"Created new bytecode generator for ${classes.size} classes.")
val bytecodeWriter = initBytecodeWriter(sortedClasses filter isJavaEntryPoint)
val plainCodeGen = new JPlainBuilder(bytecodeWriter)
val mirrorCodeGen = new JMirrorBuilder(bytecodeWriter)
val beanInfoCodeGen = new JBeanInfoBuilder(bytecodeWriter)
- while(!sortedClasses.isEmpty) {
- val c = sortedClasses.head
-
+ def emitFor(c: IClass) {
if (isStaticModule(c.symbol) && isTopLevelModule(c.symbol)) {
- if (c.symbol.companionClass == NoSymbol) {
- mirrorCodeGen.genMirrorClass(c.symbol, c.cunit)
- } else {
- log("No mirror class for module with linked class: " + c.symbol.fullName)
- }
+ if (c.symbol.companionClass == NoSymbol)
+ mirrorCodeGen genMirrorClass (c.symbol, c.cunit)
+ else
+ log(s"No mirror class for module with linked class: ${c.symbol.fullName}")
}
+ plainCodeGen genClass c
+ if (c.symbol hasAnnotation BeanInfoAttr) beanInfoCodeGen genBeanInfoClass c
+ }
- plainCodeGen.genClass(c)
-
- if (c.symbol hasAnnotation BeanInfoAttr) {
- beanInfoCodeGen.genBeanInfoClass(c)
+ while (!sortedClasses.isEmpty) {
+ val c = sortedClasses.head
+ try emitFor(c)
+ catch {
+ case e: FileConflictException =>
+ c.cunit.error(c.symbol.pos, s"error writing ${c.symbol}: ${e.getMessage}")
}
-
sortedClasses = sortedClasses.tail
classes -= c.symbol // GC opportunity
}
@@ -454,7 +455,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
}
// -----------------------------------------------------------------------------------------
- // utitilies useful when emitting plain, mirror, and beaninfo classes.
+ // utilities useful when emitting plain, mirror, and beaninfo classes.
// -----------------------------------------------------------------------------------------
def writeIfNotTooBig(label: String, jclassName: String, jclass: asm.ClassWriter, sym: Symbol) {
@@ -1397,7 +1398,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
addInnerClasses(clasz.symbol, jclass)
jclass.visitEnd()
writeIfNotTooBig("" + c.symbol.name, thisName, jclass, c.symbol)
-
}
/**
@@ -2903,7 +2903,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
JAVA_LANG_OBJECT.getInternalName,
EMPTY_STRING_ARRAY)
- log("Dumping mirror class for '%s'".format(mirrorName))
+ log(s"Dumping mirror class for '$mirrorName'")
// typestate: entering mode with valid call sequences:
// [ visitSource ] [ visitOuterClass ] ( visitAnnotation | visitAttribute )*
@@ -2926,8 +2926,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
mirrorClass.visitEnd()
writeIfNotTooBig("" + modsym.name, mirrorName, mirrorClass, modsym)
}
-
-
} // end of class JMirrorBuilder
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
index 86ee7939c8..17e679b5dd 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
@@ -172,8 +172,7 @@ trait ContextErrors {
assert(!foundType.isErroneous && !req.isErroneous, (foundType, req))
issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(foundType, req, infer.isPossiblyMissingArgs(foundType, req))) )
- if (settings.explaintypes.value)
- explainTypes(foundType, req)
+ infer.explainTypes(foundType, req)
}
def WithFilterError(tree: Tree, ex: AbsTypeError) = {
@@ -1273,11 +1272,12 @@ trait ContextErrors {
// not exactly an error generator, but very related
// and I dearly wanted to push it away from Macros.scala
private def checkSubType(slot: String, rtpe: Type, atpe: Type) = {
- val ok = if (macroDebugVerbose || settings.explaintypes.value) {
- if (rtpe eq atpe) println(rtpe + " <: " + atpe + "?" + EOL + "true")
+ val ok = if (macroDebugVerbose) {
withTypesExplained(rtpe <:< atpe)
} else rtpe <:< atpe
if (!ok) {
+ if (!macroDebugVerbose)
+ explainTypes(rtpe, atpe)
compatibilityError("type mismatch for %s: %s does not conform to %s".format(slot, abbreviateCoreAliases(rtpe.toString), abbreviateCoreAliases(atpe.toString)))
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 15ed784ae0..f1b80d9f1c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -313,8 +313,10 @@ trait Infer extends Checkable {
*/
)
- def explainTypes(tp1: Type, tp2: Type) =
- withDisambiguation(List(), tp1, tp2)(global.explainTypes(tp1, tp2))
+ def explainTypes(tp1: Type, tp2: Type) = {
+ if (context.reportErrors)
+ withDisambiguation(List(), tp1, tp2)(global.explainTypes(tp1, tp2))
+ }
/* -- Tests & Checks---------------------------------------------------- */
diff --git a/test/files/neg/abstract-explaintypes.check b/test/files/neg/abstract-explaintypes.check
new file mode 100644
index 0000000000..59c1ad2378
--- /dev/null
+++ b/test/files/neg/abstract-explaintypes.check
@@ -0,0 +1,11 @@
+abstract-explaintypes.scala:6: error: type mismatch;
+ found : A
+ required: A.this.T
+ def foo2: T = bar().baz();
+ ^
+abstract-explaintypes.scala:9: error: type mismatch;
+ found : A
+ required: A.this.T
+ def foo5: T = baz().baz();
+ ^
+two errors found
diff --git a/test/files/neg/abstract-explaintypes.flags b/test/files/neg/abstract-explaintypes.flags
new file mode 100644
index 0000000000..b36707c7cf
--- /dev/null
+++ b/test/files/neg/abstract-explaintypes.flags
@@ -0,0 +1 @@
+-explaintypes
diff --git a/test/files/neg/abstract-explaintypes.scala b/test/files/neg/abstract-explaintypes.scala
new file mode 100644
index 0000000000..f8ecae16fa
--- /dev/null
+++ b/test/files/neg/abstract-explaintypes.scala
@@ -0,0 +1,11 @@
+trait A {
+ type T <: A;
+ def baz(): A;
+ def bar(): T;
+ def foo1: A = bar().bar();
+ def foo2: T = bar().baz();
+ def foo3 = bar().baz();
+ def foo4: A = baz().bar();
+ def foo5: T = baz().baz();
+ def foo6 = baz().baz();
+}
diff --git a/test/files/pos/t6123-explaintypes-implicits.flags b/test/files/pos/t6123-explaintypes-implicits.flags
new file mode 100644
index 0000000000..b36707c7cf
--- /dev/null
+++ b/test/files/pos/t6123-explaintypes-implicits.flags
@@ -0,0 +1 @@
+-explaintypes
diff --git a/test/files/pos/t6123-explaintypes-implicits.scala b/test/files/pos/t6123-explaintypes-implicits.scala
new file mode 100644
index 0000000000..5242b443d5
--- /dev/null
+++ b/test/files/pos/t6123-explaintypes-implicits.scala
@@ -0,0 +1,13 @@
+object ImplicitBugReport {
+ trait Exp[+T]
+ trait CanBuildExp[-Elem, +To] extends (Exp[Elem] => To)
+ trait TraversableExp[T, ExpT <: Exp[T]] extends Exp[Traversable[T]]
+
+ implicit def canBuildExp[T]: CanBuildExp[T, Exp[T]] = ???
+ implicit def canBuildExpTrav[T, ExpT <: Exp[T]](implicit c: CanBuildExp[T, ExpT]): CanBuildExp[Traversable[T], TraversableExp[T, ExpT]] = ???
+ def toExpTempl[T, That](t: T)(implicit c: CanBuildExp[T, That]): That = ???
+
+ def testBug() {
+ val a1 = toExpTempl(Seq(1, 2, 3, 5))
+ }
+}
diff --git a/test/files/pos/t6123-explaintypes-macros.flags b/test/files/pos/t6123-explaintypes-macros.flags
new file mode 100644
index 0000000000..b36707c7cf
--- /dev/null
+++ b/test/files/pos/t6123-explaintypes-macros.flags
@@ -0,0 +1 @@
+-explaintypes
diff --git a/test/files/pos/t6123-explaintypes-macros.scala b/test/files/pos/t6123-explaintypes-macros.scala
new file mode 100644
index 0000000000..e650ad2038
--- /dev/null
+++ b/test/files/pos/t6123-explaintypes-macros.scala
@@ -0,0 +1,7 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.Context
+
+object Macros {
+ def printf(format: String, params: Any*): Unit = macro printf_impl
+ def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = ???
+}
diff --git a/test/files/run/t5717.scala b/test/files/run/t5717.scala
new file mode 100755
index 0000000000..a0997f5a49
--- /dev/null
+++ b/test/files/run/t5717.scala
@@ -0,0 +1,21 @@
+import scala.tools.partest._
+import java.io.File
+
+object Test extends StoreReporterDirectTest {
+ def code = ???
+
+ def compileCode(code: String) = {
+ val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
+ compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
+ }
+ // TODO
+ // Don't assume output is on physical disk
+ // Let the compiler tell us output dir
+ // val sc = newCompiler("-cp", classpath, "-d", testOutput.path)
+ // val out = sc.settings.outputDirs.getSingleOutput.get
+ def show(): Unit = {
+ // Don't crash when we find a file 'a' where package 'a' should go.
+ scala.reflect.io.File(testOutput.path + "/a").writeAll("a")
+ compileCode("package a { class B }")
+ }
+}