diff options
author | Martin Odersky <odersky@gmail.com> | 2004-01-08 15:52:45 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-01-08 15:52:45 +0000 |
commit | d8888a99cf2675e698744d1f21f90cdee42609b1 (patch) | |
tree | 621ef130c1e2d1fd21475f19036a2119cb2a4ba1 /sources | |
parent | abdb5cc6bb86908c0a8a1d9e9ebd038e08c33964 (diff) | |
download | scala-d8888a99cf2675e698744d1f21f90cdee42609b1.tar.gz scala-d8888a99cf2675e698744d1f21f90cdee42609b1.tar.bz2 scala-d8888a99cf2675e698744d1f21f90cdee42609b1.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/examples/parsers.scala | 12 | ||||
-rw-r--r-- | sources/scala/tools/scalac/typechecker/Analyzer.scala | 42 |
2 files changed, 39 insertions, 15 deletions
diff --git a/sources/examples/parsers.scala b/sources/examples/parsers.scala index 3112e0346d..bef1e960cb 100644 --- a/sources/examples/parsers.scala +++ b/sources/examples/parsers.scala @@ -1,5 +1,8 @@ package examples; -abstract class Parsers[intype] { + +abstract class Parsers { + + type intype; abstract class Parser { @@ -39,7 +42,7 @@ abstract class Parsers[intype] { def rep1(p: Parser): Parser = p &&& rep(p); // p+ = p p* } -abstract class ListParsers[intype] extends Parsers[intype] { +abstract class ListParsers extends Parsers { def chr(p: char => boolean): Parser; @@ -55,7 +58,8 @@ abstract class ListParsers[intype] extends Parsers[intype] { def expr : Parser = ident ||| number ||| list; } -class ParseString(s: String) extends Parsers[int] { +class ParseString(s: String) extends Parsers { + type intype = int; val input = 0; def chr(p: char => boolean) = new Parser { def apply(in: int): Parser#Result = @@ -68,7 +72,7 @@ object Test { def main(args: Array[String]): unit = if (args.length == 1) { - val ps = new ListParsers[int] with ParseString(args(0)); + val ps = new ListParsers with ParseString(args(0)); ps.exprs(input) match { case Some(n) => System.out.println("parsed: " + args(0).substring(0, n)); diff --git a/sources/scala/tools/scalac/typechecker/Analyzer.scala b/sources/scala/tools/scalac/typechecker/Analyzer.scala index bfc9082add..c80cf712ab 100644 --- a/sources/scala/tools/scalac/typechecker/Analyzer.scala +++ b/sources/scala/tools/scalac/typechecker/Analyzer.scala @@ -250,6 +250,7 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( if (isAccessible(sym, site, sitetype)) { symtype } else { + System.out.println(sym.flags & (PRIVATE | PROTECTED));//debug error(pos, "" + sym + " cannot be accessed in " + sitetype.widen()); Type.ErrorType } @@ -288,8 +289,9 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( accessWithin(owner) || ((sym.flags & PRIVATE) == 0) && - sitetype.symbol().isSubClass(owner) && - (site.isInstanceOf[Tree$Super] || isSubClassOfEnclosing(sitetype.symbol())) + (site.isInstanceOf[Tree$Super] || + (sitetype.symbol().isSubClass(owner) && + isSubClassOfEnclosing(sitetype.symbol()))) } } @@ -1021,9 +1023,10 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( var rhs = _rhs; var restype: Type = null; pushContext(tree, sym, new Scope(context.scope)); - if (name == Names.CONSTRUCTOR) + if (name == Names.CONSTRUCTOR) { context.enclClass.owner.flags = context.enclClass.owner.flags | INCONSTRUCTOR; + } val tparamSyms = enterParams(tparams); val vparamSyms = enterParams(vparams); if (tpe != Tree.Empty) { @@ -1031,8 +1034,10 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( (tree.asInstanceOf[Tree$DefDef]).tpe = tpe; restype = tpe.getType(); } else if (name == Names.CONSTRUCTOR) { - restype = context.enclClass.owner.getType().subst( - context.enclClass.owner.typeParams(), tparamSyms); + if (context.enclClass.owner.typeParams().length != 0) + error(tree.pos, "secondary constructors for parameterized classes not yet implemented"); + restype = context.enclClass.owner.getType();/*.subst( + context.enclClass.owner.typeParams(), tparamSyms)*/; context.enclClass.owner.flags = context.enclClass.owner.flags & ~INCONSTRUCTOR; } else { @@ -2449,14 +2454,29 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( val constr: Symbol = c.allConstructors(); val fn0: Tree = fn1; fn1 = gen.mkRef(fn1.pos, pre, constr); - fn1 match { - case Tree$Select(fn1qual, _) => + if (constr.owner().isPackage()) { + var c = context; + while (c != Context.NONE && + !c.tree.isInstanceOf[Tree$ClassDef] && + !c.tree.isInstanceOf[Tree$Template]) + c = c.outer; + if (c.owner.isConstructor()) + // we are in a superclass constructor call + fn1.setType(checkAccessible( + fn1.pos, constr, fn1.getType(), make.Super(tree.pos, Names.EMPTY.toTypeName(), Names.EMPTY.toTypeName()), c.owner.constructorClass().typeConstructor())); + else fn1.setType(checkAccessible( - fn1.pos, constr, fn1.getType(), fn1qual, fn1qual.getType())); - case _ => - if (constr.owner().isPackage()) + fn1.pos, constr, fn1.getType(), c.tree, c.owner.typeConstructor())); + } else { + fn1 match { + case Tree$Select(fn1qual, _) => fn1.setType(checkAccessible( - fn1.pos, constr, fn1.getType(), Tree.Empty, constr.owner().getType())); + 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 { |