diff options
author | Martin Odersky <odersky@gmail.com> | 2003-08-15 10:25:51 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-08-15 10:25:51 +0000 |
commit | 260757086149e48d2dbe955335ba959e874a6452 (patch) | |
tree | 57c5c0e150aabf04e57dff04a83170e22c7be9f2 | |
parent | 396a60a22c2724676071449d55aa9b29cd8c4322 (diff) | |
download | scala-260757086149e48d2dbe955335ba959e874a6452.tar.gz scala-260757086149e48d2dbe955335ba959e874a6452.tar.bz2 scala-260757086149e48d2dbe955335ba959e874a6452.zip |
*** empty log message ***
-rw-r--r-- | doc/reference/reference.verb.tex | 14 | ||||
-rw-r--r-- | sources/meta/scalac/ast/Tree.java | 2 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 44 | ||||
-rw-r--r-- | sources/scalac/typechecker/Infer.java | 53 |
4 files changed, 75 insertions, 38 deletions
diff --git a/doc/reference/reference.verb.tex b/doc/reference/reference.verb.tex index 1a72c7d9d7..01d1440090 100644 --- a/doc/reference/reference.verb.tex +++ b/doc/reference/reference.verb.tex @@ -1243,8 +1243,10 @@ be omitted. If the lower bound \verb@L@ is missing, the bottom type the top type \verb@scala.Any@ is assumed. A {\em type alias} \verb@type t = T@ defines \verb@t@ to be an alias -name for the type \verb@T@. Type declarations and type aliases are -collectively called {\em type bindings}. +name for the type \verb@T@. The left hand side of a type alias may +have a type parameter clause, e.g. \verb@type t[tps] = T@. The scope +of a type parameter extends over the right hand side \verb@T@ and the +type parameter clause \verb@tps@ itself. The scope rules for definitions (\sref{sec:defs}) and type parameters (\sref{sec:funsigs}) make it possible that a type name appears in its @@ -2498,17 +2500,17 @@ class Shape { ... } trait Bordered extends Shape { - val thinkness: int + val thickness: int; def equals(other: Any) = other match { - case that: Bordered => this.thickness == that.thickness; + case that: Bordered => this.thickness == that.thickness case _ => false } ... } trait Colored extends Shape { - val color: Color + val color: Color; def equals(other: Any) = other match { - case that: Colored => this.color == that.color; + case that: Colored => this.color == that.color case _ => false } ... diff --git a/sources/meta/scalac/ast/Tree.java b/sources/meta/scalac/ast/Tree.java index 44fe88f9d2..39f15f0bfc 100644 --- a/sources/meta/scalac/ast/Tree.java +++ b/sources/meta/scalac/ast/Tree.java @@ -327,7 +327,7 @@ public class Tree { setDescription("Type selection"). setRange(Phase.PARSER, Phase.REFCHECK). addField(t_TypeTree, "qualifier"). - addField(t_TypeName, "selector", SymName); + addField(t_TestName, "selector", SymName); n_FunType. setDescription("Function type"). diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 86a9461f27..fa1d391f1c 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -2127,7 +2127,12 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (c.kind == CLASS) { c.initialize(); Tree fn0 = fn1; - fn1 = gen.mkRef(tree.pos, pre, c.allConstructors()); + Symbol constr = c.allConstructors(); + fn1 = gen.mkRef(fn1.pos, pre, constr); + switch (fn1) { + case Select(Tree fn1qual, _): + checkAccessible(fn1.pos, constr, fn1qual); + } if (tsym == c) { switch (fn0) { case AppliedType(_, Tree[] targs): @@ -2137,7 +2142,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { // it was an alias type // todo: handle overloaded constructors fn1 = gen.TypeApply( - fn1, gen.mkTypes(tree.pos, argtypes)); + fn1, gen.mkTypes(fn1.pos, argtypes)); if (tsym.typeParams().length != 0 && !(fn0 instanceof AppliedType)) fn1.type = Type.PolyType( @@ -2350,8 +2355,39 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { .setType(checkObjectType(tree.pos, ref1.type.resultType())); case SelectFromType(Tree qual, Name name): - Tree qual1 = transform(qual, TYPEmode); - return transformSelect(tree, qual1, name); + if ((mode & TYPEmode) != 0) { + Tree qual1 = transform(qual, TYPEmode); + return transformSelect(tree, qual1, name); + } else { + Symbol clazz = context.enclClass.owner; + if (clazz != null) { + Type[] parents = clazz.parents(); + Name qualname = ((Ident) qual).name; + for (int i = 1; i < parents.length; i++) { + if (parents[i].symbol().name == qualname) { + Symbol bsym = parents[i].lookup(name); + if (bsym.kind == NONE) { + return error(tree.pos, + decode(name) + " is not a member of " + + parents[i]); + } else if ((bsym.flags & PRIVATE) != 0) { + return error(tree.pos, + decode(name) + " is not accessible in " + + parents[i]); + } + return gen.Select( + tree.pos, + gen.mkStableId(tree.pos, clazz.thisType()), + bsym); + } + } + return error(qual.pos, + qual + " does not name a mixin base class"); + } else { + return error(tree.pos, tree + + " can be used only in a class, object, or template"); + } + } case CompoundType(Tree[] parents, Tree[] refinements): Tree[] parents1 = transform(parents, TYPEmode); diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java index 30ed7086a4..c14515f841 100644 --- a/sources/scalac/typechecker/Infer.java +++ b/sources/scalac/typechecker/Infer.java @@ -449,39 +449,38 @@ public class Infer implements Modifiers, Kinds { : !upper; tvars[i] = Type.NoType; Type bound = up ? tparams[i].info() : tparams[i].loBound(); - if (up && bound.symbol() != Global.instance.definitions.ANY_CLASS || - !up && bound.symbol() != Global.instance.definitions.ALL_CLASS) { - boolean cyclic = false; - for (int j = 0; j < tvars.length; j++) { - if (bound.contains(tparams[j]) || - up && tparams[j].loBound().isSameAs(tparams[i].type()) || - !up && tparams[j].info().isSameAs(tparams[i].type())) { - cyclic |= tvars[j] == Type.NoType; - solve(tparams, upper, variances, tvars, j); - } + boolean cyclic = false; + for (int j = 0; j < tvars.length; j++) { + if (bound.contains(tparams[j]) || + up && tparams[j].loBound().isSameAs(tparams[i].type()) || + !up && tparams[j].info().isSameAs(tparams[i].type())) { + cyclic |= tvars[j] == Type.NoType; + solve(tparams, upper, variances, tvars, j); } - if (!cyclic) { - if (up) { + } + if (!cyclic) { + if (up) { + if (bound.symbol() != Global.instance.definitions.ANY_CLASS) constr.hibounds = new Type.List( bound.subst(tparams, tvars), constr.hibounds); - for (int j = 0; j < tvars.length; j++) { - if (tparams[j].loBound().isSameAs( - tparams[i].type())) { - constr.hibounds = new Type.List( - tparams[j].type().subst(tparams, tvars), - constr.hibounds); - } + for (int j = 0; j < tvars.length; j++) { + if (tparams[j].loBound().isSameAs( + tparams[i].type())) { + constr.hibounds = new Type.List( + tparams[j].type().subst(tparams, tvars), + constr.hibounds); } - } else { + } + } else { + if (bound.symbol() != Global.instance.definitions.ALL_CLASS) constr.lobounds = new Type.List( bound.subst(tparams, tvars), constr.lobounds); - for (int j = 0; j < tvars.length; j++) { - if (tparams[j].info().isSameAs( - tparams[i].type())) { - constr.lobounds = new Type.List( - tparams[j].type().subst(tparams, tvars), - constr.lobounds); - } + for (int j = 0; j < tvars.length; j++) { + if (tparams[j].info().isSameAs( + tparams[i].type())) { + constr.lobounds = new Type.List( + tparams[j].type().subst(tparams, tvars), + constr.lobounds); } } } |