fixed text in error message

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25488 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
michelou 2011-08-11 21:40:15 +00:00
parent b24e9e66f1
commit e1f07dc4dd
5 changed files with 54 additions and 79 deletions

View File

@ -10,8 +10,7 @@ import symtab.Flags._
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import annotation.tailrec import annotation.tailrec
/** This trait ... /**
*
* @author Martin Odersky * @author Martin Odersky
* @version 1.0 * @version 1.0
*/ */
@ -36,13 +35,13 @@ trait Contexts { self: Analyzer =>
var lastAccessCheckDetails: String = "" var lastAccessCheckDetails: String = ""
/** List of symbols to import from in a root context. Typically that /** List of symbols to import from in a root context. Typically that
* is java.lang, scala, and scala.Predef, in that order. Exceptions: * is `java.lang`, `scala`, and [[scala.Predef]], in that order. Exceptions:
* *
* -- if -Yno-imports is given, nothing is imported * - if option `-Yno-imports` is given, nothing is imported
* -- if the unit is java defined, only java.lang is imported * - if the unit is java defined, only `java.lang` is imported
* -- if -Yno-predef is given, if the unit has an import of Predef * - if option `-Yno-predef` is given, if the unit has an import of Predef
* among its leading imports, or if the unit is scala.ScalaObject * among its leading imports, or if the unit is [[scala.ScalaObject]]
* or scala.Predef, Predef is not imported. * or [[scala.Predef]], `Predef` is not imported.
*/ */
protected def rootImports(unit: CompilationUnit, tree: Tree): List[Symbol] = { protected def rootImports(unit: CompilationUnit, tree: Tree): List[Symbol] = {
import definitions._ import definitions._
@ -128,26 +127,25 @@ trait Contexts { self: Analyzer =>
var typingIndentLevel: Int = 0 var typingIndentLevel: Int = 0
def typingIndent = " " * typingIndentLevel def typingIndent = " " * typingIndentLevel
def undetparamsString = if (undetparams.isEmpty) "" else undetparams.mkString("undetparams=", ", ", "") def undetparamsString =
if (undetparams.isEmpty) ""
else undetparams.mkString("undetparams=", ", ", "")
def undetparams = _undetparams def undetparams = _undetparams
def undetparams_=(ps: List[Symbol]) = { def undetparams_=(ps: List[Symbol]) = { _undetparams = ps }
//System.out.println("undetparams = " + ps);//debug
_undetparams = ps
}
def extractUndetparams() = { def extractUndetparams() = {
val tparams = undetparams val tparams = undetparams
undetparams = List() undetparams = List()
tparams tparams
} }
def withoutReportingErrors[T](op: => T): T = { def withoutReportingErrors[T](op: => T): T = {
val saved = reportGeneralErrors val saved = reportGeneralErrors
reportGeneralErrors = false reportGeneralErrors = false
try op try op
finally reportGeneralErrors = saved finally reportGeneralErrors = saved
} }
def withImplicitsDisabled[T](op: => T): T = { def withImplicitsDisabled[T](op: => T): T = {
val saved = implicitsEnabled val saved = implicitsEnabled
implicitsEnabled = false implicitsEnabled = false
@ -155,14 +153,6 @@ trait Contexts { self: Analyzer =>
finally implicitsEnabled = saved finally implicitsEnabled = saved
} }
/**
* @param unit ...
* @param tree ...
* @param owner ...
* @param scope ...
* @param imports ...
* @return ...
*/
def make(unit: CompilationUnit, tree: Tree, owner: Symbol, def make(unit: CompilationUnit, tree: Tree, owner: Symbol,
scope: Scope, imports: List[ImportInfo]): Context = { scope: Scope, imports: List[ImportInfo]): Context = {
val c = new Context val c = new Context
@ -171,7 +161,7 @@ trait Contexts { self: Analyzer =>
c.owner = owner c.owner = owner
c.scope = scope c.scope = scope
c.outer = this c.outer = this
tree match { tree match {
case Template(_, _, _) | PackageDef(_, _) => case Template(_, _, _) | PackageDef(_, _) =>
c.enclClass = c c.enclClass = c
@ -218,13 +208,12 @@ trait Contexts { self: Analyzer =>
def makeNewImport(imp: Import): Context = def makeNewImport(imp: Import): Context =
make(unit, imp, owner, scope, new ImportInfo(imp, depth) :: imports) make(unit, imp, owner, scope, new ImportInfo(imp, depth) :: imports)
def make(tree: Tree, owner: Symbol, scope: Scope): Context = { def make(tree: Tree, owner: Symbol, scope: Scope): Context =
if (tree == this.tree && owner == this.owner && scope == this.scope) this if (tree == this.tree && owner == this.owner && scope == this.scope) this
else make0(tree, owner, scope) else make0(tree, owner, scope)
}
private def make0(tree : Tree, owner : Symbol, scope : Scope) : Context = { private def make0(tree: Tree, owner: Symbol, scope: Scope): Context =
make(unit, tree, owner, scope, imports) make(unit, tree, owner, scope, imports)
}
def makeNewScope(tree: Tree, owner: Symbol): Context = def makeNewScope(tree: Tree, owner: Symbol): Context =
make(tree, owner, new Scope(scope)) make(tree, owner, new Scope(scope))
@ -274,12 +263,10 @@ trait Contexts { self: Analyzer =>
argContext argContext
} }
private def diagString =
if (diagnostic.isEmpty) ""
else diagnostic.mkString("\n","\n", "")
private def addDiagString(msg: String) = { private def addDiagString(msg: String) = {
val ds = diagString val ds =
if (diagnostic.isEmpty) ""
else diagnostic.mkString("\n","\n", "")
if (msg endsWith ds) msg else msg + ds if (msg endsWith ds) msg else msg + ds
} }
@ -301,18 +288,11 @@ trait Contexts { self: Analyzer =>
ErrorTree(msg) setPos pos ErrorTree(msg) setPos pos
} }
*/ */
def warning(pos: Position, msg: String) = { def warning(pos: Position, msg: String) = {
if (reportGeneralErrors) unit.warning(pos, msg) if (reportGeneralErrors) unit.warning(pos, msg)
} }
/**
* @param pos ...
* @param pre ...
* @param sym1 ...
* @param sym2 ...
* @param rest ...
*/
def ambiguousError(pos: Position, pre: Type, sym1: Symbol, sym2: Symbol, rest: String) { def ambiguousError(pos: Position, pre: Type, sym1: Symbol, sym2: Symbol, rest: String) {
val (reportPos, msg) = ( val (reportPos, msg) = (
if (sym1.hasDefaultFlag && sym2.hasDefaultFlag && sym1.enclClass == sym2.enclClass) { if (sym1.hasDefaultFlag && sym2.hasDefaultFlag && sym1.enclClass == sym2.enclClass) {
@ -358,7 +338,7 @@ trait Contexts { self: Analyzer =>
val scopingCtx = val scopingCtx =
if (owner.isConstructor) nextEnclosing(c => !c.tree.isInstanceOf[Block]) if (owner.isConstructor) nextEnclosing(c => !c.tree.isInstanceOf[Block])
else this else this
scopingCtx.outer scopingCtx.outer
} }
@ -385,8 +365,8 @@ trait Contexts { self: Analyzer =>
c c
} }
/** Return closest enclosing context that defines a subclass of `clazz` or a companion /** Return the closest enclosing context that defines a subclass of `clazz`
* object thereof, or NoContext if no such context exists * or a companion object thereof, or `NoContext` if no such context exists.
*/ */
def enclosingSubClassContext(clazz: Symbol): Context = { def enclosingSubClassContext(clazz: Symbol): Context = {
var c = this.enclClass var c = this.enclClass
@ -395,13 +375,8 @@ trait Contexts { self: Analyzer =>
c c
} }
/** Is <code>sym</code> accessible as a member of tree `site` with type /** Is `sym` accessible as a member of tree `site` with type
* <code>pre</code> in current context? * `pre` in current context?
*
* @param sym ...
* @param pre ...
* @param superAccess ...
* @return ...
*/ */
def isAccessible(sym: Symbol, pre: Type, superAccess: Boolean = false): Boolean = { def isAccessible(sym: Symbol, pre: Type, superAccess: Boolean = false): Boolean = {
lastAccessCheckDetails = "" lastAccessCheckDetails = ""
@ -449,20 +424,21 @@ trait Contexts { self: Analyzer =>
/** Is protected access to target symbol permitted */ /** Is protected access to target symbol permitted */
def isProtectedAccessOK(target: Symbol) = { def isProtectedAccessOK(target: Symbol) = {
val c = enclosingSubClassContext(sym.owner) val c = enclosingSubClassContext(sym.owner)
if (c == NoContext) if (c == NoContext)
lastAccessCheckDetails = lastAccessCheckDetails =
"\n Access to protected "+target+" not permitted because"+ "\n Access to protected "+target+" not permitted because"+
"\n "+"enclosing class "+this.enclClass.owner+this.enclClass.owner.locationString+" is not a subclass of "+ "\n "+"enclosing "+this.enclClass.owner+
this.enclClass.owner.locationString+" is not a subclass of "+
"\n "+sym.owner+sym.owner.locationString+" where target is defined" "\n "+sym.owner+sym.owner.locationString+" where target is defined"
c != NoContext && c != NoContext &&
{ {
target.isType || { // allow accesses to types from arbitrary subclasses fixes #4737 target.isType || { // allow accesses to types from arbitrary subclasses fixes #4737
val res = val res =
isSubClassOrCompanion(pre.widen.typeSymbol, c.owner) || isSubClassOrCompanion(pre.widen.typeSymbol, c.owner) ||
c.owner.isModuleClass && c.owner.isModuleClass &&
isSubClassOrCompanion(pre.widen.typeSymbol, c.owner.linkedClassOfClass) isSubClassOrCompanion(pre.widen.typeSymbol, c.owner.linkedClassOfClass)
if (!res) if (!res)
lastAccessCheckDetails = lastAccessCheckDetails =
"\n Access to protected "+target+" not permitted because"+ "\n Access to protected "+target+" not permitted because"+
"\n prefix type "+pre.widen+" does not conform to"+ "\n prefix type "+pre.widen+" does not conform to"+
"\n "+c.owner+c.owner.locationString+" where the access take place" "\n "+c.owner+c.owner.locationString+" where the access take place"
@ -473,7 +449,7 @@ trait Contexts { self: Analyzer =>
(pre == NoPrefix) || { (pre == NoPrefix) || {
val ab = sym.accessBoundary(sym.owner) val ab = sym.accessBoundary(sym.owner)
( (ab.isTerm || ab == definitions.RootClass) ( (ab.isTerm || ab == definitions.RootClass)
|| (accessWithin(ab) || accessWithinLinked(ab)) && || (accessWithin(ab) || accessWithinLinked(ab)) &&
( !sym.hasLocalFlag ( !sym.hasLocalFlag
@ -518,7 +494,7 @@ trait Contexts { self: Analyzer =>
private var implicitsCache: List[List[ImplicitInfo]] = null private var implicitsCache: List[List[ImplicitInfo]] = null
private var implicitsRunId = NoRunId private var implicitsRunId = NoRunId
def resetCache() { def resetCache() {
implicitsRunId = NoRunId implicitsRunId = NoRunId
implicitsCache = null implicitsCache = null
@ -562,7 +538,6 @@ trait Contexts { self: Analyzer =>
} }
def implicitss: List[List[ImplicitInfo]] = { def implicitss: List[List[ImplicitInfo]] = {
if (implicitsRunId != currentRunId) { if (implicitsRunId != currentRunId) {
implicitsRunId = currentRunId implicitsRunId = currentRunId
implicitsCache = List() implicitsCache = List()
@ -603,8 +578,8 @@ trait Contexts { self: Analyzer =>
def lookup(name: Name, expectedOwner: Symbol) = { def lookup(name: Name, expectedOwner: Symbol) = {
var res: Symbol = NoSymbol var res: Symbol = NoSymbol
var ctx = this var ctx = this
while(res == NoSymbol && ctx.outer != ctx) { while (res == NoSymbol && ctx.outer != ctx) {
val s = ctx.scope.lookup(name) val s = ctx.scope lookup name
if (s != NoSymbol && s.owner == expectedOwner) if (s != NoSymbol && s.owner == expectedOwner)
res = s res = s
else else
@ -612,21 +587,21 @@ trait Contexts { self: Analyzer =>
} }
res res
} }
} } //class Context
class ImportInfo(val tree: Import, val depth: Int) { class ImportInfo(val tree: Import, val depth: Int) {
/** The prefix expression */ /** The prefix expression */
def qual: Tree = tree.symbol.info match { def qual: Tree = tree.symbol.info match {
case ImportType(expr) => expr case ImportType(expr) => expr
case ErrorType => tree setType NoType // fix for #2870 case ErrorType => tree setType NoType // fix for #2870
case _ => throw new FatalError("symbol " + tree.symbol + " has bad type: " + tree.symbol.info);//debug case _ => throw new FatalError("symbol " + tree.symbol + " has bad type: " + tree.symbol.info) //debug
} }
/** Is name imported explicitly, not via wildcard? */ /** Is name imported explicitly, not via wildcard? */
def isExplicitImport(name: Name): Boolean = def isExplicitImport(name: Name): Boolean =
tree.selectors exists (_.rename == name.toTermName) tree.selectors exists (_.rename == name.toTermName)
/** The symbol with name <code>name</code> imported from import clause /** The symbol with name `name` imported from import clause `tree`.
* <code>tree</code>.
*/ */
def importedSymbol(name: Name): Symbol = { def importedSymbol(name: Name): Symbol = {
var result: Symbol = NoSymbol var result: Symbol = NoSymbol
@ -651,7 +626,7 @@ trait Contexts { self: Analyzer =>
private def transformImport(selectors: List[ImportSelector], sym: Symbol): List[Symbol] = selectors match { private def transformImport(selectors: List[ImportSelector], sym: Symbol): List[Symbol] = selectors match {
case List() => List() case List() => List()
case List(ImportSelector(nme.WILDCARD, _, _, _)) => List(sym) case List(ImportSelector(nme.WILDCARD, _, _, _)) => List(sym)
case ImportSelector(from, _, to, _) :: _ if (from == sym.name) => case ImportSelector(from, _, to, _) :: _ if from == sym.name =>
if (to == nme.WILDCARD) List() if (to == nme.WILDCARD) List()
else { val sym1 = sym.cloneSymbol; sym1.name = to; List(sym1) } else { val sym1 = sym.cloneSymbol; sym1.name = to; List(sym1) }
case _ :: rest => transformImport(rest, sym) case _ :: rest => transformImport(rest, sym)

View File

@ -1,12 +1,12 @@
bug3714-neg.scala:17: error: value break in class BreakImpl cannot be accessed in BreakImpl bug3714-neg.scala:17: error: value break in class BreakImpl cannot be accessed in BreakImpl
Access to protected value break not permitted because Access to protected value break not permitted because
enclosing class object Test is not a subclass of enclosing object Test is not a subclass of
class BreakImpl where target is defined class BreakImpl where target is defined
case b: BreakImpl => b.break case b: BreakImpl => b.break
^ ^
bug3714-neg.scala:25: error: value break in class BreakImpl cannot be accessed in BreakImpl bug3714-neg.scala:25: error: value break in class BreakImpl cannot be accessed in BreakImpl
Access to protected value break not permitted because Access to protected value break not permitted because
enclosing class object Test is not a subclass of enclosing object Test is not a subclass of
class BreakImpl where target is defined class BreakImpl where target is defined
case b: BreakImpl => b.break case b: BreakImpl => b.break
^ ^

View File

@ -3,19 +3,19 @@ protected-constructors.scala:17: error: too many arguments for constructor Foo1:
^ ^
protected-constructors.scala:18: error: constructor Foo2 in class Foo2 cannot be accessed in object P protected-constructors.scala:18: error: constructor Foo2 in class Foo2 cannot be accessed in object P
Access to protected constructor Foo2 not permitted because Access to protected constructor Foo2 not permitted because
enclosing class object P in package hungus is not a subclass of enclosing object P in package hungus is not a subclass of
class Foo2 in package dingus where target is defined class Foo2 in package dingus where target is defined
val foo2 = new Foo2("abc") val foo2 = new Foo2("abc")
^ ^
protected-constructors.scala:19: error: class Foo3 in object Ding cannot be accessed in object dingus.Ding protected-constructors.scala:19: error: class Foo3 in object Ding cannot be accessed in object dingus.Ding
Access to protected class Foo3 not permitted because Access to protected class Foo3 not permitted because
enclosing class object P in package hungus is not a subclass of enclosing object P in package hungus is not a subclass of
object Ding in package dingus where target is defined object Ding in package dingus where target is defined
val foo3 = new Ding.Foo3("abc") val foo3 = new Ding.Foo3("abc")
^ ^
protected-constructors.scala:15: error: class Foo3 in object Ding cannot be accessed in object dingus.Ding protected-constructors.scala:15: error: class Foo3 in object Ding cannot be accessed in object dingus.Ding
Access to protected class Foo3 not permitted because Access to protected class Foo3 not permitted because
enclosing class object P in package hungus is not a subclass of enclosing object P in package hungus is not a subclass of
object Ding in package dingus where target is defined object Ding in package dingus where target is defined
class Bar3 extends Ding.Foo3("abc") class Bar3 extends Ding.Foo3("abc")
^ ^

View File

@ -3,13 +3,13 @@ S.scala:5: error: method f in object J cannot be accessed in object bippy.J
^ ^
S.scala:6: error: method f1 in object S1 cannot be accessed in object bippy.S1 S.scala:6: error: method f1 in object S1 cannot be accessed in object bippy.S1
Access to protected method f1 not permitted because Access to protected method f1 not permitted because
enclosing class object Test in package bippy is not a subclass of enclosing object Test in package bippy is not a subclass of
object S1 in package bippy where target is defined object S1 in package bippy where target is defined
S1.f1() S1.f1()
^ ^
S.scala:8: error: method f2 in class S2 cannot be accessed in bippy.S2 S.scala:8: error: method f2 in class S2 cannot be accessed in bippy.S2
Access to protected method f2 not permitted because Access to protected method f2 not permitted because
enclosing class object Test in package bippy is not a subclass of enclosing object Test in package bippy is not a subclass of
class S2 in package bippy where target is defined class S2 in package bippy where target is defined
x.f2() x.f2()
^ ^

View File

@ -1,6 +1,6 @@
t3934.scala:15: error: method f2 in class J cannot be accessed in test.J t3934.scala:15: error: method f2 in class J cannot be accessed in test.J
Access to protected method f2 not permitted because Access to protected method f2 not permitted because
enclosing class class S1 in package nest is not a subclass of enclosing class S1 in package nest is not a subclass of
class J in package test where target is defined class J in package test where target is defined
def g2(x: J) = x.f2() def g2(x: J) = x.f2()
^ ^