From 098db0fd0bb6ad0ddf978b5fc719fa6a8c2954f0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 Mar 2007 13:40:08 +0000 Subject: fixed bug1024. --- src/compiler/scala/tools/nsc/CompilationUnits.scala | 5 ++++- src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 9 +++++++++ src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala | 2 +- src/compiler/scala/tools/nsc/symtab/Scopes.scala | 2 +- src/compiler/scala/tools/nsc/transform/Constructors.scala | 3 +++ src/compiler/scala/tools/nsc/typechecker/Infer.scala | 11 ++++------- test/files/neg/bug1024.check | 4 ++++ test/files/neg/bug1024.scala | 3 +++ 8 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 test/files/neg/bug1024.check create mode 100644 test/files/neg/bug1024.scala diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index e76f95d207..2250ac379c 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -23,7 +23,10 @@ trait CompilationUnits requires Global { /** the content of the compilation unit in tree form */ var body: Tree = EmptyTree - val depends = new HashSet[AbstractFile] + /** Note: depends now contains toplevel classes. + * To get their sourcefiles, you need to dereference with .sourcefile + */ + val depends = new HashSet[Symbol] def position(pos: int) = new Position(source, pos) diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index d4ff2d1737..aba34b0d51 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -182,6 +182,15 @@ abstract class TreeInfo { case _ => false } + /** can this type be a type pattern */ + def mayBeTypePat(tree: Tree): boolean = tree match { + case CompoundTypeTree(Template(tps, List())) => tps exists mayBeTypePat + case Annotated(_, tp) => mayBeTypePat(tp) + case AppliedTypeTree(constr, args) => mayBeTypePat(constr) || args.exists(.isInstanceOf[Bind]) + case SelectFromTypeTree(tp, _) => mayBeTypePat(tp) + case _ => false + } + /** Is this pattern node a catch-all (wildcard or variable) pattern? */ def isDefaultCase(cdef: CaseDef) = cdef match { case CaseDef(Ident(nme.WILDCARD), EmptyTree, _) => true diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index f65cb3b05b..e1b72f557d 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -62,7 +62,7 @@ abstract class TreeBuilder { override def traverse(tree: Tree): unit = tree match { case Bind(name, Typed(tree1, tpt)) => if ((name != nme.WILDCARD) && (buf.elements forall (name !=))) - buf += (name, tpt) + buf += (name, if (treeInfo.mayBeTypePat(tpt)) TypeTree() else tpt) traverse(tree1) case Bind(name, tree1) => if ((name != nme.WILDCARD) && (buf.elements forall (name !=))) diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index cfaccf44f1..6d66875474 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -178,7 +178,7 @@ trait Scopes requires SymbolTable { elems = e.next } else { var e1 = elems - while (e1.next != e) e1 = e1.next; + while (e1.next != e) e1 = e1.next e1.next = e.next } if (hashtable ne null) { diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 76ad75e317..606a252b24 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -179,6 +179,9 @@ abstract class Constructors extends Transform { paramInits ::: constrPrefixBuf.toList ::: constrStatBuf.toList, constrBody.expr)); + for (val sym <- clazz.info.decls.toList) + if (!isAccessed(sym)) clazz.info.decls unlink sym + copy.Template(impl, impl.parents, defBuf.toList filter (stat => isAccessed(stat.symbol))) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index d79bb134ad..64e49e4b35 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -336,13 +336,10 @@ trait Infer requires Analyzer { errorTree(tree, underlying(sym).toString() + " cannot be accessed in " + (if (sym.isClassConstructor) context.enclClass.owner else pre.widen) + explanation) - if (context.unit != null) sym.toplevelClass match { - case clazz : ClassSymbol => - if (clazz.sourceFile != null) { - context.unit.depends += clazz.sourceFile - } - case _ => - } + + if (context.unit != null) + context.unit.depends += sym.toplevelClass + val sym1 = sym filter (alt => context.isAccessible(alt, pre, site.isInstanceOf[Super])) if (sym1 == NoSymbol) { if (settings.debug.value) { diff --git a/test/files/neg/bug1024.check b/test/files/neg/bug1024.check new file mode 100644 index 0000000000..74ff983647 --- /dev/null +++ b/test/files/neg/bug1024.check @@ -0,0 +1,4 @@ +bug1024.scala:2: error: type _ escapes its defining scope as part of type (scala.List[_], scala.Int) + val (a: List[_], b) = (List(1 ,2 ,3 ), 4) + ^ +one error found diff --git a/test/files/neg/bug1024.scala b/test/files/neg/bug1024.scala new file mode 100644 index 0000000000..bddb21f727 --- /dev/null +++ b/test/files/neg/bug1024.scala @@ -0,0 +1,3 @@ +object Test { + val (a: List[_], b) = (List(1 ,2 ,3 ), 4) +} -- cgit v1.2.3