From 41d7105a224d18a98cde2c6ca1867231ddf49f45 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 25 Nov 2003 17:35:21 +0000 Subject: *** empty log message *** --- doc/reference/ScalaReference.tex | 72 ++++++++++++++++----- sources/scala/collection/Map.scala | 1 + sources/scala/tools/scalac/ast/parser/Parser.scala | 75 ++++++++++++++-------- .../scala/tools/scalac/typechecker/Analyzer.scala | 63 +++++++++--------- .../tools/scalac/typechecker/DeSugarize.scala | 9 +-- sources/scala/tools/scalac/typechecker/Infer.scala | 30 +++------ sources/scalac/ast/parser/Parser.java | 28 +++++--- sources/scalac/symtab/Modifiers.java | 2 +- sources/scalac/symtab/Symbol.java | 1 + sources/scalac/typechecker/Analyzer.java | 5 ++ test/files/pos/bug208.scala | 8 --- test/pos/bug208.scala | 8 --- 12 files changed, 175 insertions(+), 127 deletions(-) delete mode 100644 test/files/pos/bug208.scala delete mode 100644 test/pos/bug208.scala diff --git a/doc/reference/ScalaReference.tex b/doc/reference/ScalaReference.tex index c108b8e745..5e0fa75442 100644 --- a/doc/reference/ScalaReference.tex +++ b/doc/reference/ScalaReference.tex @@ -946,6 +946,30 @@ the type definition ~\lstinline@type T, U <: B@~ expands to ~\lstinline@type T; type U <: B@. +If an element in such a sequence introduces only the defined name, +possibly with some type or value parameters, but leaves out any +aditional parts in the definition, then those parts are implicitly +copied from the next subsequent sequence element which consists of +more than just a defined name and parameters. Examples: +\begin{itemize} +\item[] +The variable declaration ~\lstinline@var x, y: int@~ +expands to ~\lstinline@var x: int; var y: int@. +\item[] +The value definition ~\lstinline@val x, y: int = 1@~ +expands to ~\lstinline@val x: int = 1; val y: int = 1@. +\item[] +The class definition ~\lstinline@case class X(), Y(n: int) extends Z@~ expands to +~\lstinline@case class X extends Z; case class Y(n: int) extends Z@. +\item +The object definition ~\lstinline@case object Red, Green, Blue extends Color@~ +expands to +\begin{\lstlisting} +case object Red extends Color; +case object Green extends Color; +case object Blue extends Color . +\end{lstisting} + \section{Value Declarations and Definitions} \label{sec:valdef} @@ -1023,6 +1047,11 @@ val xs = x$\Dollar$._2; | id `:' Type `=' `_' \end{lstlisting} +A sequence of variable declarations \listinline@var x$_1$, ..., x$_n$: T@ +is equivalent to + + + A variable declaration ~\lstinline@var $x$: $T$@~ is equivalent to declarations of a {\em getter function} $x$ and a {\em setter function} \lstinline@$x$_=@, defined as follows: @@ -2228,7 +2257,8 @@ module FileSystem with { \syntax\begin{lstlisting} Expr ::= [Bindings `=>'] Expr - | if `(' Expr `)' Expr [[`;'] else Expr] + | Expr1 + Expr1 ::= if `(' Expr `)' Expr [[`;'] else Expr] | try `{' block `}' [catch Expr] [finally Expr] | while '(' Expr ')' Expr | do Expr [`;'] while `(' Expr ')' @@ -2254,7 +2284,9 @@ module FileSystem with { | BlockExpr BlockExpr ::= `{' CaseClause {CaseClause} `}' | `{' Block `}' - Block ::= {BlockStat `;'} [Expr] + Block ::= {BlockStat `;'} [ResultExpr] + ResultExpr ::= Expr1 + | Bindings `=>' Block Exprs ::= Expr {`,' Expr} \end{lstlisting} @@ -2677,7 +2709,7 @@ override a member of $C$. \syntax\begin{lstlisting} BlockExpr ::= `{' Block `}' - Block ::= [{BlockStat `;'} Expr] + Block ::= [{BlockStat `;'} ResultExpr] \end{lstlisting} A block expression ~\lstinline@{$s_1$; $\ldots$; $s_n$; $e\,$}@~ is constructed from a @@ -2796,7 +2828,7 @@ where $x$ is a fresh name. \section{Typed Expressions} \syntax\begin{lstlisting} - Expr ::= PostfixExpr [`:' Type1] + Expr1 ::= PostfixExpr [`:' Type1] \end{lstlisting} The typed expression $e: T$ has type $T$. The type of @@ -2814,7 +2846,7 @@ the expression is the value of $e$ converted to type $T$. \section{Assignments} \syntax\begin{lstlisting} - Expr ::= Designator `=' Expr + Expr1 ::= Designator `=' Expr | SimpleExpr ArgumentExpr `=' Expr \end{lstlisting} @@ -2886,7 +2918,7 @@ def matmul(xss: Array[Array[double]], yss: Array[Array[double]]) = { \section{Conditional Expressions} \syntax\begin{lstlisting} - Expr ::= if `(' Expr `)' Expr [[`;'] else Expr] + Expr1 ::= if `(' Expr `)' Expr [[`;'] else Expr] \end{lstlisting} The conditional expression ~\lstinline@if ($e_1$) $e_2$ else $e_3$@~ chooses @@ -2913,7 +2945,7 @@ $e_2$ is also expected to conform to type \code{unit}. \section{While Loop Expressions} \syntax\begin{lstlisting} - Expr ::= while `(' Expr ')' Expr + Expr1 ::= while `(' Expr ')' Expr \end{lstlisting} The while loop expression ~\lstinline@while ($e_1$) $e_2$@~ is typed and @@ -2941,7 +2973,7 @@ expression ~\lstinline@(y = 1/x)@~ will be evaluated in the body of \section{Do Loop Expressions} \syntax\begin{lstlisting} - Expr ::= do Expr [`;'] while `(' Expr ')' + Expr1 ::= do Expr [`;'] while `(' Expr ')' \end{lstlisting} The do loop expression ~\lstinline@do $e_1$ while ($e_2$)@~ is typed and @@ -2951,7 +2983,7 @@ A semicolon preceding the \code{while} symbol of a do loop expression is ignored \section{Comprehensions} \syntax\begin{lstlisting} - Expr ::= for `(' Enumerators `)' [yield] Expr + Expr1 ::= for `(' Enumerators `)' [yield] Expr Enumerator ::= Generator {`;' Enumerator} Enumerator ::= Generator | Expr @@ -3115,7 +3147,7 @@ The code above makes use of the fact that \code{map}, \code{flatmap}, \section{Return Expressions} \syntax\begin{lstlisting} - Expr ::= return [Expr] + Expr1 ::= return [Expr] \end{lstlisting} A return expression ~\lstinline@return $e$@~ must occur inside the @@ -3132,7 +3164,7 @@ a return expression is \code{scala.All}. \section{Throw Expressions} \syntax\begin{lstlisting} - Expr ::= throw Expr + Expr1 ::= throw Expr \end{lstlisting} A throw expression ~\lstinline@throw $e$@~ evaluates the expression @@ -3149,7 +3181,7 @@ is \code{scala.All}. \section{Try Expressions}\label{sec:try} \syntax\begin{lstlisting} - Expr ::= try `{' block `}' [catch Expr] [finally Expr] + Expr1 ::= try `{' Block `}' [catch Expr] [finally Expr] \end{lstlisting} A try expression ~\lstinline@try { $b$ } catch $e$@~ evaluates the block @@ -3189,7 +3221,8 @@ for ~\lstinline@try { try { $b$ } catch $e_1$ } finally $e_2$@. \label{sec:closures} \syntax\begin{lstlisting} - Expr ::= [Bindings `=>'] Expr + Expr1 ::= Bindings `=>' Expr + ResultExpr ::= Bindings `=>' Block Bindings ::= `(' Binding {`,' Binding `)' | id [`:' Type1] Binding ::= id [`:' Type] @@ -4191,8 +4224,9 @@ grammar. Exprs ::= Expr {`,' Expr} Expr ::= Bindings `=>' Expr - | if `(' Expr `)' Expr [[`;'] else Expr] - | try `{' block `}' [catch Expr] [finally Expr] + | Expr1 + Expr1 ::= if `(' Expr1 `)' Expr [[`;'] else Expr] + | try `{' Block `}' [catch Expr] [finally Expr] | do Expr [`;'] while `(' Expr ')' | for `(' Enumerators `)' (do | yield) Expr | return [Expr] @@ -4217,12 +4251,14 @@ grammar. | BlockExpr BlockExpr ::= `{' CaseClause {CaseClause} `}' | `{' Block `}' - Block ::= {BlockStat `;'} [Expr] + Block ::= {BlockStat `;'} [ResultExpr] BlockStat ::= Import | Def | {LocalModifier} ClsDef - | Expr + | Expr1 | + ResultExpr ::= Expr1 + | Bindings `=>' Block Enumerators ::= Generator {`;' Enumerator} Enumerator ::= Generator @@ -4994,3 +5030,5 @@ package scala.List[a extends Comparable[a]] with Comparable[List[a]] with { } \end{lstlisting} } + + diff --git a/sources/scala/collection/Map.scala b/sources/scala/collection/Map.scala index 343e4d342a..ff156cf3b5 100644 --- a/sources/scala/collection/Map.scala +++ b/sources/scala/collection/Map.scala @@ -177,3 +177,4 @@ trait Map[A, +B] with PartialFunction[A, B] } + "}"; } + diff --git a/sources/scala/tools/scalac/ast/parser/Parser.scala b/sources/scala/tools/scalac/ast/parser/Parser.scala index 279b0e7fe4..a889dcd819 100644 --- a/sources/scala/tools/scalac/ast/parser/Parser.scala +++ b/sources/scala/tools/scalac/ast/parser/Parser.scala @@ -192,6 +192,25 @@ class Parser(unit: Unit) { n } + /** Create a tree representing a packaging + */ + def makePackaging(pos: int, pkg0: Tree, stats0: Array[Tree]): Tree = { + var pkg = pkg0; + var stats = stats0; + while (true) { + val templ = make.Template(pos, Tree.EMPTY_ARRAY, stats); + pkg match { + case Tree$Select(qual, name) => + stats = NewArray.Tree( + make.PackageDef(pos, make.Ident(pkg.pos, name), templ)); + pkg = qual; + case _ => + return make.PackageDef(pos, pkg, templ); + } + } + null//dummy + } + /** Create tree representing binary operation expression or pattern. */ def makeBinop(isExpr: boolean, pos: int, left: Tree, op: Name, right: Tree): Tree = @@ -728,9 +747,8 @@ class Parser(unit: Unit) { /** Exprs ::= Expr {`,' Expr} * | Expr `:' `_' `*' */ - def exprs(): Array[Tree] = { - val ts = new TreeList(); - ts.append(expr(true)); + def exprs(): Array[Tree] = { val ts = new TreeList(); + ts.append(expr(true, false)); while (s.token == COMMA) { s.nextToken(); ts.append(expr()); @@ -738,26 +756,29 @@ class Parser(unit: Unit) { ts.toArray() } - /** Expr ::= Bindings `=>' Expr - * | if `(' Expr `)' Expr [[`;'] else Expr] - * | try `{' block `}' [catch Expr] [finally Expr] - * | while `(' Expr `)' Expr - * | do Expr [`;'] while `(' Expr `)' - * | for `(' Enumerators `)' (do | yield) Expr - * | throw Expr - * | return [Expr] - * | [SimpleExpr `.'] Id `=' Expr - * | SimpleExpr ArgumentExprs `=' Expr - * | PostfixExpr [`:' Type1] - * Bindings ::= Id [`:' Type1] - * | `(' [Binding {`,' Binding}] `)' - * Binding ::= Id [`:' Type] + /** Expr ::= Bindings `=>' Expr + * | Expr1 + * ResultExpr ::= Bindings `=>' Block + * | Expr1 + * Expr1 ::= (' Expr `)' Expr [[`;'] else Expr] + * | try `{' block `}' [catch Expr] [finally Expr] + * | while `(' Expr `)' Expr + * | do Expr [`;'] while `(' Expr `)' + * | for `(' Enumerators `)' (do | yield) Expr + * | throw Expr + * | return [Expr] + * | [SimpleExpr `.'] Id `=' Expr + * | SimpleExpr ArgumentExprs `=' Expr + * | PostfixExpr [`:' Type1] + * Bindings ::= Id [`:' Type1] + * | `(' [Binding {`,' Binding}] `)' + * Binding ::= Id [`:' Type] */ def expr(): Tree = - expr(false); + expr(false, false); - def expr(isArgument: boolean): Tree = { + def expr(isArgument: boolean, isInBlock: boolean): Tree = { if (s.token == IF) { val pos = s.skipToken(); accept(LPAREN); @@ -845,7 +866,9 @@ class Parser(unit: Unit) { } } if (s.token == ARROW) { - t = make.Function(s.skipToken(), convertToParams(t), expr()); + val arrowpos = s.skipToken(); + t = make.Function(arrowpos, convertToParams(t), + if (isInBlock) block(arrowpos) else expr()); } t } @@ -1784,7 +1807,7 @@ class Parser(unit: Unit) { accept(LBRACE); val stats = topStatSeq(); accept(RBRACE); - make.PackageDef(pos, pkg, make.Template(pos, Tree.EMPTY_ARRAY, stats)); + makePackaging(pos, pkg, stats); } /** TopStatSeq ::= [TopStat {`;' TopStat}] @@ -1870,7 +1893,7 @@ class Parser(unit: Unit) { stats.append(importClause()); accept(SEMI); } else if (isExprIntro()) { - stats.append(expr()); + stats.append(expr(false, true)); if (s.token != RBRACE && s.token != CASE) accept(SEMI); } else if (isDefIntro()) { stats.append(defOrDcl(0)); @@ -1901,15 +1924,11 @@ class Parser(unit: Unit) { val pkg = qualId(); if (s.token == SEMI) { s.nextToken(); - NewArray.Tree( - make.PackageDef( - pos, pkg, make.Template(pos, Tree.EMPTY_ARRAY, topStatSeq()))); + NewArray.Tree(makePackaging(pos, pkg, topStatSeq())); } else { val stats = new TreeList(); accept(LBRACE); - stats.append( - make.PackageDef( - pos, pkg, make.Template(pos, Tree.EMPTY_ARRAY, topStatSeq()))); + stats.append(makePackaging(pos, pkg, topStatSeq())); accept(RBRACE); stats.append(topStatSeq()); stats.toArray() diff --git a/sources/scala/tools/scalac/typechecker/Analyzer.scala b/sources/scala/tools/scalac/typechecker/Analyzer.scala index b7b8f74f43..24f2dfadd0 100644 --- a/sources/scala/tools/scalac/typechecker/Analyzer.scala +++ b/sources/scala/tools/scalac/typechecker/Analyzer.scala @@ -58,8 +58,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) while (n > 0) { // this calls apply(u) for every unit `u'. val l = global.units.length; val newUnits = new Array[Unit](l + n); - System.arraycopy( - global.units.asInstanceOf[Array[Object]], 0, newUnits.asInstanceOf[Array[Object]], 0, l); + System.arraycopy(global.units, 0, newUnits, 0, l); var i = 0; while (i < n) { newUnits(i + l) = descr.newSources.get(i).asInstanceOf[Unit]; i = i + 1 @@ -213,7 +212,8 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) /** Check that `sym' is accessible as a member of tree `site' in current context. */ - def checkAccessible(pos: int, sym: Symbol, symtype: Type, site: Tree): Type = { + def checkAccessible(pos: int, sym: Symbol, symtype: Type, site: Tree, sitetype: Type): Type = { + //System.out.println("check acc " + sym);//DEBUG if ((sym.owner().flags & INCONSTRUCTOR) != 0 && !(sym.kind == TYPE && sym.isParameter()) && site.isInstanceOf[Tree$This]) { @@ -224,19 +224,19 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) case Type$OverloadedType(alts, alttypes) => var nacc: int = 0; var i = 0; while (i < alts.length) { - if (isAccessible(alts(i), site)) + if (isAccessible(alts(i), site, sitetype)) nacc = nacc + 1; i = i + 1 } if (nacc == 0) { - error(pos, "" + sym + " cannot be accessed in " + site.getType().widen()); + error(pos, "" + sym + " cannot be accessed in " + sitetype.widen()); Type.ErrorType } else { val alts1: Array[Symbol] = new Array[Symbol](nacc); val alttypes1: Array[Type] = new Array[Type](nacc); nacc = 0; var i = 0; while (i < alts.length) { - if (isAccessible(alts(i), site)) { + if (isAccessible(alts(i), site, sitetype)) { alts1(nacc) = alts(i); alttypes1(nacc) = alttypes(i); nacc = nacc + 1; @@ -246,10 +246,10 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) new Type$OverloadedType(alts1, alttypes1) } case _ => - if (isAccessible(sym, site)) { + if (isAccessible(sym, site, sitetype)) { symtype } else { - error(pos, "" + sym + " cannot be accessed in " + site.getType().widen()); + error(pos, "" + sym + " cannot be accessed in " + sitetype.widen()); Type.ErrorType } } @@ -258,7 +258,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) /** Is `sym' accessible as a member of tree `site' in current context? */ - private def isAccessible(sym: Symbol, site: Tree): boolean = { + private def isAccessible(sym: Symbol, site: Tree, sitetype: Type): boolean = { /** Are we inside definition of `owner'? */ @@ -282,13 +282,14 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) (sym.flags & (PRIVATE | PROTECTED)) == 0 || - accessWithin(sym.owner()) - || - ((sym.flags & PRIVATE) == 0) && - site.getType().symbol().isSubClass( - if (sym.isConstructor()) sym.constructorClass() else sym.owner()) && - (site.isInstanceOf[Tree$Super] || - isSubClassOfEnclosing(site.getType().symbol())) + {val owner = if (sym.isConstructor()) sym.constructorClass() + else sym.owner(); + accessWithin(owner) + || + ((sym.flags & PRIVATE) == 0) && + sitetype.symbol().isSubClass(owner) && + (site.isInstanceOf[Tree$Super] || isSubClassOfEnclosing(sitetype.symbol())) + } } // Checking methods ---------------------------------------------------------- @@ -840,6 +841,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) error(tree.pos, "constructor definition not allowed here"); } sym = context.enclClass.owner.addConstructor(); + sym.flags = sym.flags | mods; } else { sym = TermSymbol.define(tree.pos, name, owner, mods, context.scope); } @@ -1172,8 +1174,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) selftype match { case Type$CompoundType(parts, members) => val parts1 = new Array[Type](parts.length + 1); - System.arraycopy(parts.asInstanceOf[Array[Object]], 0, - parts1.asInstanceOf[Array[Object]], 0, parts.length); + System.arraycopy(parts, 0, parts1, 0, parts.length); parts1(parts.length) = clazz.getType(); sym.setInfo(Type.compoundType(parts1, members)); @@ -1345,7 +1346,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) if (applyMeth != Symbol.NONE) { val applyType: Type = checkAccessible( tree.pos, applyMeth, tree.getType().memberType(applyMeth), - tree); + tree, tree.getType()); val tree1 = make.Select(tree.pos, tree, Names.apply) .setSymbol(applyMeth) .setType(applyType); @@ -1399,7 +1400,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) if (coerceMeth != Symbol.NONE) { val coerceType: Type = checkAccessible( tree.pos, coerceMeth, tree.getType().memberType(coerceMeth), - tree); + tree, tree.getType()); val tree1 = make.Select(tree.pos, tree, Names.coerce) .setSymbol(coerceMeth) .setType(coerceType); @@ -1510,7 +1511,9 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) (if (sym.isType()) sym.typeConstructor() else sym.getType()) .asSeenFrom(pre, sym.owner()); if (qual != Tree.Empty) - symtype = checkAccessible(tree.pos, sym, symtype, qual); + symtype = checkAccessible(tree.pos, sym, symtype, qual, qual.getType()); + else if (sym.owner().isPackage()) + symtype = checkAccessible(tree.pos, sym, symtype, qual, sym.owner().getType()); if (symtype == Type.NoType) return error(tree.pos, "not found: " + decode(name)); //System.out.println(name + ":" + symtype);//DEBUG @@ -1541,7 +1544,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) if (symtype == Type.NoType) return error(tree.pos, "not found: " + decode(name)); else - symtype = checkAccessible(tree.pos, sym, symtype, qual); + symtype = checkAccessible(tree.pos, sym, symtype, qual, qual.getType()); //System.out.println(sym.name + ":" + symtype);//DEBUG if (uninst.length != 0) { symtype match { @@ -1619,8 +1622,7 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) // find out why if (stat1 != stat && stats1 == stats) { stats1 = new Array[Tree](stats.length); - System.arraycopy(stats.asInstanceOf[Array[Object]], 0, - stats1.asInstanceOf[Array[Object]], 0, i); + System.arraycopy(stats, 0, stats1, 0, i); } stats1(i) = stat1; i = i + 1 @@ -1793,12 +1795,8 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) var tparams2: Array[Symbol] = tparams1; if (tparams.length != 0) { tparams2 = new Array[Symbol](tparams.length + tparams1.length); - System.arraycopy(tparams.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], 0, - tparams.length); - System.arraycopy(tparams1.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], tparams.length, - tparams1.length); + System.arraycopy(tparams, 0, tparams2, 0, tparams.length); + System.arraycopy(tparams1, 0, tparams2, tparams.length, tparams1.length); } transformArgs(pos, meth, tparams2, restp, argMode, args, pt) @@ -2402,8 +2400,11 @@ class Analyzer(global: Global, descr: AnalyzerPhase) extends Transformer(global) fn1 match { case Tree$Select(fn1qual, _) => fn1.setType(checkAccessible( - fn1.pos, constr, fn1.getType(), fn1qual)); + fn1.pos, constr, fn1.getType(), fn1qual, fn1qual.getType())); case _ => + if (constr.owner().isPackage()) + fn1.setType(checkAccessible( + fn1.pos, constr, fn1.getType(), Tree.Empty, constr.owner().getType())); } if (tsym == c) { fn0 match { diff --git a/sources/scala/tools/scalac/typechecker/DeSugarize.scala b/sources/scala/tools/scalac/typechecker/DeSugarize.scala index e22751e057..3358b7ac3b 100644 --- a/sources/scala/tools/scalac/typechecker/DeSugarize.scala +++ b/sources/scala/tools/scalac/typechecker/DeSugarize.scala @@ -85,8 +85,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: Infer def FunType(tree: Tree): Tree = tree match { case Tree$FunType(argtpes, restpe) => val types = new Array[Tree](argtpes.length + 1); - System.arraycopy(argtpes.asInstanceOf[Array[Object]], 0, - types.asInstanceOf[Array[Object]], 0, argtpes.length); + System.arraycopy(argtpes, 0, types, 0, argtpes.length); types(argtpes.length) = restpe; make.AppliedType( tree.pos, @@ -228,8 +227,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: Infer // e.update val update: Tree = make.Select(fn.pos, fn, Names.update); val args1 = new Array[Tree](args.length + 1); - System.arraycopy(args.asInstanceOf[Array[Object]], 0, - args1.asInstanceOf[Array[Object]], 0, args.length); + System.arraycopy(args, 0, args1, 0, args.length); args1(args.length) = rhs; make.Apply(tree.pos, update, args1); } @@ -437,8 +435,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: Infer val tree1: Tree = liftout(tree, defs); if (tree1 != tree && trees1 == trees) { trees1 = new Array[Tree](trees.length); - System.arraycopy(trees.asInstanceOf[Array[Object]], 0, - trees1.asInstanceOf[Array[Object]], 0, trees.length); + System.arraycopy(trees, 0, trees1, 0, trees.length); } trees1(i) = tree1; } diff --git a/sources/scala/tools/scalac/typechecker/Infer.scala b/sources/scala/tools/scalac/typechecker/Infer.scala index fe29f71b89..5fcc008e54 100644 --- a/sources/scala/tools/scalac/typechecker/Infer.scala +++ b/sources/scala/tools/scalac/typechecker/Infer.scala @@ -601,11 +601,9 @@ class Infer(global: Global, gen: TreeGen, make: TreeFactory) { //new Printer().print(tree1);//DEBUG //System.out.println(ArrayApply.toString(targs) + "/" + i + "/" + ArrayApply.toString(tparams));//DEBUG val tparams1: Array[Symbol] = new Array[Symbol](tparams.length - i); - System.arraycopy(tparams.asInstanceOf[Array[Object]], i, - tparams1.asInstanceOf[Array[Object]], 0, tparams1.length); + System.arraycopy(tparams, i, tparams1, 0, tparams1.length); val targs1: Array[Type] = new Array[Type](tparams.length - i); - System.arraycopy(targs.asInstanceOf[Array[Object]], i, - targs1.asInstanceOf[Array[Object]], 0, targs1.length); + System.arraycopy(targs, i, targs1, 0, targs1.length); tree1 = substituter.apply(tree1, tparams1, targs1); } if (0 < i) { @@ -631,10 +629,8 @@ class Infer(global: Global, gen: TreeGen, make: TreeFactory) { restype match { case Type$PolyType(tparams1, restype1) => val tparams2: Array[Symbol] = new Array[Symbol](tparams.length + tparams1.length); - System.arraycopy(tparams.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], 0, tparams.length); - System.arraycopy(tparams1.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], tparams.length, tparams1.length); + System.arraycopy(tparams, 0, tparams2, 0, tparams.length); + System.arraycopy(tparams1, 0, tparams2, tparams.length, tparams1.length); argumentTypeInstance(tparams2, restype1, pt1, pt2); case _ => @@ -662,10 +658,8 @@ class Infer(global: Global, gen: TreeGen, make: TreeFactory) { restype match { case Type$PolyType(tparams1, restype1) => val tparams2: Array[Symbol] = new Array[Symbol](tparams.length + tparams1.length); - System.arraycopy(tparams.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], 0, tparams.length); - System.arraycopy(tparams1.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], tparams.length, tparams1.length); + System.arraycopy(tparams, 0, tparams2, 0, tparams.length); + System.arraycopy(tparams1, 0, tparams2, tparams.length, tparams1.length); exprInstance(tree, tparams2, restype1, pt) case _ => val targs: Array[Type] = exprTypeArgs(tparams, restype, pt); @@ -686,10 +680,8 @@ class Infer(global: Global, gen: TreeGen, make: TreeFactory) { restype match { case Type$PolyType(tparams1, restype1) => val tparams2: Array[Symbol] = new Array[Symbol](tparams.length + tparams1.length); - System.arraycopy(tparams.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], 0, tparams.length); - System.arraycopy(tparams1.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], tparams.length, tparams1.length); + System.arraycopy(tparams, 0, tparams2, 0, tparams.length); + System.arraycopy(tparams1, 0, tparams2, tparams.length, tparams1.length); methodInstance(tree, tparams2, restype1, argtypes, pt) case Type$MethodType(params, restpe) => @@ -726,10 +718,8 @@ class Infer(global: Global, gen: TreeGen, make: TreeFactory) { restype match { case Type$PolyType(tparams1, restype1) => val tparams2: Array[Symbol] = new Array[Symbol](tparams.length + tparams1.length); - System.arraycopy(tparams.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], 0, tparams.length); - System.arraycopy(tparams1.asInstanceOf[Array[Object]], 0, - tparams2.asInstanceOf[Array[Object]], tparams.length, tparams1.length); + System.arraycopy(tparams, 0, tparams2, 0, tparams.length); + System.arraycopy(tparams1, 0, tparams2, tparams.length, tparams1.length); constructorInstance(tree, tparams2, restype1, pt) case _ => diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 9dacca3bc1..9fa2e92dda 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -209,6 +209,23 @@ public class Parser implements Tokens { return Name.fromString("x$" + (fresh++)); } + /** Create a tree representing a packaging + */ + Tree makePackaging(int pos, Tree pkg, Tree[] stats) { + while (true) { + Template templ = make.Template(pos, Tree.EMPTY_ARRAY, stats); + switch (pkg) { + case Select(Tree qual, Name name): + stats = new Tree[]{ + make.PackageDef(pos, make.Ident(pkg.pos, name), templ)}; + pkg = qual; + break; + default: + return make.PackageDef(pos, pkg, templ); + } + } + } + /** Create tree representing binary operation expression or pattern. */ Tree makeBinop(boolean isExpr, int pos, Tree left, Name op, Tree right) { @@ -1938,8 +1955,7 @@ public class Parser implements Tokens { accept(LBRACE); Tree[] stats = topStatSeq(); accept(RBRACE); - return - make.PackageDef(pos, pkg, make.Template(pos, Tree.EMPTY_ARRAY, stats)); + return makePackaging(pos, pkg, stats); } /** TopStatSeq ::= [TopStat {`;' TopStat}] @@ -2057,15 +2073,11 @@ public class Parser implements Tokens { Tree pkg = qualId(); if (s.token == SEMI) { s.nextToken(); - return new Tree[]{ - make.PackageDef( - pos, pkg, make.Template(pos, Tree.EMPTY_ARRAY, topStatSeq()))}; + return new Tree[]{makePackaging(pos, pkg, topStatSeq())}; } else { TreeList stats = new TreeList(); accept(LBRACE); - stats.append( - make.PackageDef( - pos, pkg, make.Template(pos, Tree.EMPTY_ARRAY, topStatSeq()))); + stats.append(makePackaging(pos, pkg, topStatSeq())); accept(RBRACE); stats.append(topStatSeq()); return stats.toArray(); diff --git a/sources/scalac/symtab/Modifiers.java b/sources/scalac/symtab/Modifiers.java index 292eb28bbc..0e835610e3 100644 --- a/sources/scalac/symtab/Modifiers.java +++ b/sources/scalac/symtab/Modifiers.java @@ -66,7 +66,7 @@ public interface Modifiers { int SOURCEFLAGS = 0x00000077 | DEF | REPEATED | MODUL | MUTABLE | PACKAGE | PARAM | TRAIT | COVARIANT | CONTRAVARIANT; // these modifiers can be set in source programs. int ACCESSFLAGS = PRIVATE | PROTECTED; int VARIANCES = COVARIANT | CONTRAVARIANT; - int CONSTRFLAGS = ACCESSFLAGS | CASE | JAVA | STATIC; + int CONSTRFLAGS = CASE | JAVA | STATIC; public static class Helper { diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index 3e6ac35ba8..8687fa39ba 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -1471,6 +1471,7 @@ public abstract class TypeSymbol extends Symbol { Symbol[] alts = allConstructors().alternativeSymbols(); for (int i = 1; i < alts.length; i++) { Symbol constr = other.addConstructor(); + constr.flags = other.flags; constr.setInfo( fixConstrType( alts[i].info().cloneType(alts[i], constr), diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 44b4773b87..b11f3ac85a 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -1276,6 +1276,11 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { try { tree = infer.exprInstance(tree, tparams, restp, pt); } catch (Type.Error ex) { + Context c = context; + while (c != Context.NONE) { + System.out.println("context: " + c.owner); + c = c.outer; + } tree = error(tree.pos, ex.msg); } return adapt(tree, mode, pt); diff --git a/test/files/pos/bug208.scala b/test/files/pos/bug208.scala deleted file mode 100644 index 99c7faefe2..0000000000 --- a/test/files/pos/bug208.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - def f = { - object o { - trait T; - } - o - } -} diff --git a/test/pos/bug208.scala b/test/pos/bug208.scala deleted file mode 100644 index 99c7faefe2..0000000000 --- a/test/pos/bug208.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - def f = { - object o { - trait T; - } - o - } -} -- cgit v1.2.3