summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala5
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala17
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala7
-rw-r--r--test/files/neg/bug765.check4
-rw-r--r--test/files/neg/bug765.scala7
-rw-r--r--test/files/pos/bug759.scala6
9 files changed, 47 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index c4a70304d0..b61d6ae483 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -131,7 +131,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
private def newLineName = {
val num = nextLineNo
nextLineNo = nextLineNo + 1
- "line" + num
+ compiler.nme.INTERPRETER_LINE_PREFIX + num
}
/** import statements that should be used for submitted code */
@@ -389,7 +389,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
val trees = parse(line)
/** name to use for the object that will compute "line" */
- def objectName = lineName + "$object" // make it unlikely to clash with user variables
+ def objectName = lineName + compiler.nme.INTERPRETER_WRAPPER_SUFFIX // make it unlikely to clash with user variables
/** name of the object that retrieves the result from the above object */
def resultObjectName = "RequestResult$" + objectName
@@ -513,6 +513,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
// compile the main object
val objRun = new compiler.Run()
+ //Console.println("source: "+objectSourceCode) //DEBUG
objRun.compileSources(
List(new SourceFile("<console>", objectSourceCode.toCharArray))
)
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index 72432c7fe8..ee02d5fe3d 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -70,6 +70,8 @@ trait StdNames requires SymbolTable {
val EXPAND_SEPARATOR_STRING = "$$"
val TUPLE_FIELD_PREFIX_STRING = "_"
val CHECK_IF_REFUTABLE_STRING = "check$ifrefutable$"
+ val INTERPRETER_WRAPPER_SUFFIX = "$object"
+ val INTERPRETER_LINE_PREFIX = "line"
def LOCAL(clazz: Symbol) = newTermName(LOCALDUMMY_PREFIX_STRING + clazz.name)
def TUPLE_FIELD(index: int) = newTermName(TUPLE_FIELD_PREFIX_STRING + index)
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 1565e88a0b..e71134386c 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -211,6 +211,13 @@ trait Symbols requires SymbolTable {
final def isEmptyPackage = isPackage && name == nme.EMPTY_PACKAGE_NAME
final def isEmptyPackageClass = isPackageClass && name == nme.EMPTY_PACKAGE_NAME.toTypeName
+ /** Does this symbol denote a wrapper object of the interpreter or its class? */
+ final def isInterpreterWrapper =
+ (isModule || isModuleClass) &&
+ owner.isEmptyPackageClass &&
+ name.toString.startsWith(nme.INTERPRETER_LINE_PREFIX) &&
+ name.toString.endsWith(nme.INTERPRETER_WRAPPER_SUFFIX)
+
/** Does this symbol denote a stable value? */
final def isStable =
isTerm && !hasFlag(MUTABLE) && (!hasFlag(METHOD | BYNAMEPARAM) || hasFlag(STABLE))
@@ -883,7 +890,9 @@ trait Symbols requires SymbolTable {
final def fullNameString(separator: char): String = {
assert(owner != NoSymbol, this)
var str =
- if (owner.isRoot || owner.isEmptyPackageClass) simpleName.toString
+ if (owner.isRoot ||
+ owner.isEmptyPackageClass ||
+ owner.isInterpreterWrapper) simpleName.toString
else owner.enclClass.fullNameString(separator) + separator + simpleName
if (str.charAt(str.length - 1) == ' ') str = str.substring(0, str.length - 1)
str
@@ -904,7 +913,11 @@ trait Symbols requires SymbolTable {
/** String representation of location. */
final def locationString: String =
if (owner.isClass &&
- (!owner.isAnonymousClass && !owner.isRefinementClass || settings.debug.value))
+ ((!owner.isAnonymousClass &&
+ !owner.isRefinementClass &&
+ !owner.isInterpreterWrapper &&
+ !owner.isRoot &&
+ !owner.isEmptyPackageClass) || settings.debug.value))
" in " + owner else ""
/** String representation of symbol's definition following its name */
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 60f6ea424b..3c5524e88e 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -576,7 +576,7 @@ trait Types requires SymbolTable {
override def singleDeref: Type = sym.typeOfThis
override def prefixString =
if (settings.debug.value) sym.nameString + ".this."
- else if (sym.isRoot || sym.isEmptyPackageClass) ""
+ else if (sym.isRoot || sym.isEmptyPackageClass || sym.isInterpreterWrapper) ""
else if (sym.isAnonymousClass || sym.isRefinementClass) "this."
else if (sym.isPackageClass) sym.fullNameString + "."
else sym.nameString + ".this."
@@ -623,7 +623,7 @@ trait Types requires SymbolTable {
override def symbol = sym
override def prefix: Type = pre
override def prefixString: String =
- if (sym.isEmptyPackage && !settings.debug.value) ""
+ if ((sym.isEmptyPackage || sym.isInterpreterWrapper) && !settings.debug.value) ""
else pre.prefixString + sym.nameString + "."
}
@@ -976,7 +976,7 @@ trait Types requires SymbolTable {
override def prefixString =
if (settings.debug.value) super.prefixString
- else if (sym.isRoot || sym.isEmptyPackageClass ||
+ else if (sym.isRoot || sym.isEmptyPackageClass || sym.isInterpreterWrapper ||
sym.isAnonymousClass || sym.isRefinementClass) ""
else if (sym.isPackageClass) sym.fullNameString + "."
else super.prefixString;
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 3210b3982f..0a9a8912ac 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -563,7 +563,9 @@ trait Namers requires Analyzer {
val base = expr1.tpe
typer.checkStable(expr1)
def checkNotRedundant(pos: PositionType, from: Name, to: Name): boolean = {
- if (!tree.symbol.hasFlag(SYNTHETIC) && base.member(from) != NoSymbol) {
+ if (!tree.symbol.hasFlag(SYNTHETIC) &&
+ !(expr1.symbol != null && expr1.symbol.isInterpreterWrapper) &&
+ base.member(from) != NoSymbol) {
val e = context.scope.lookupEntry(to)
def warnRedundant(sym: Symbol) =
context.unit.warning(pos, "imported `"+to+
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index b9a664e753..087f5c485f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -146,8 +146,7 @@ trait Typers requires Analyzer {
val pos = if (ex.pos == NoPos) pos0 else ex.pos
ex match {
case CyclicReference(sym, info: TypeCompleter) =>
- context.unit.error(
- pos,
+ val msg =
info.tree match {
case ValDef(_, _, tpt, _) if (tpt.tpe == null) =>
"recursive "+sym+" needs type"
@@ -156,7 +155,9 @@ trait Typers requires Analyzer {
else "recursive ")+sym+" needs result type"
case _ =>
ex.getMessage()
- })
+ }
+ if (context.retyping) context.error(pos, msg)
+ else context.unit.error(pos, msg)
case _ =>
context.error(pos, ex)
}
diff --git a/test/files/neg/bug765.check b/test/files/neg/bug765.check
new file mode 100644
index 0000000000..474367c4c5
--- /dev/null
+++ b/test/files/neg/bug765.check
@@ -0,0 +1,4 @@
+bug765.scala:3 error: not found: type Bar123
+ val bar = new Bar123
+ ^
+one error found
diff --git a/test/files/neg/bug765.scala b/test/files/neg/bug765.scala
new file mode 100644
index 0000000000..f1100df55a
--- /dev/null
+++ b/test/files/neg/bug765.scala
@@ -0,0 +1,7 @@
+object test {
+ for (val e <- List()) { //required
+ val bar = new Bar123
+ val res = bar.f //required
+ ()
+ }
+}
diff --git a/test/files/pos/bug759.scala b/test/files/pos/bug759.scala
new file mode 100644
index 0000000000..2eac89cd60
--- /dev/null
+++ b/test/files/pos/bug759.scala
@@ -0,0 +1,6 @@
+object Test extends Application {
+
+ def f[A](x : => A) = x
+
+ Console.println(f(Array(42))(0))
+}