diff options
author | Martin Odersky <odersky@gmail.com> | 2014-04-21 18:10:25 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-05-08 21:51:46 +0200 |
commit | 782c24ff51865e43e34a2485dc585a757ada2c3b (patch) | |
tree | b4aab29f24af18dd4ab428c2e8169cf8fc320be2 /src | |
parent | 35366df3bed1e2a13aa41abfd0f75c7241f22197 (diff) | |
download | dotty-782c24ff51865e43e34a2485dc585a757ada2c3b.tar.gz dotty-782c24ff51865e43e34a2485dc585a757ada2c3b.tar.bz2 dotty-782c24ff51865e43e34a2485dc585a757ada2c3b.zip |
Changed handling of repeated parameters.
Previously, repeated parameters were typed as `<repeated>[T]`. The
method `underlyingWithRepeated` converts `<repeated>[T]` to `Seq[T]`.
This method was called in typedIdent, but the call was ineffective
because the type of a repeated parameter ident is a TermRef. This led
to a retyping error in Decorators.scala under -Ycheck:front.
We now distinguish between the type of the internal parameter ValDef
and the type of the parameter in the MethodType. The former has the type
`Seq[T] @dotty.annotation.internal.repeated`, the latter has the type
`<repeated>[T]`. The translation with `underlyingWithRepeated` thus
becomes unneccessary.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/annotation/internal/Repeated.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/Main.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/Trees.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 12 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 |
7 files changed, 23 insertions, 14 deletions
diff --git a/src/dotty/annotation/internal/Repeated.scala b/src/dotty/annotation/internal/Repeated.scala new file mode 100644 index 000000000..94e9df858 --- /dev/null +++ b/src/dotty/annotation/internal/Repeated.scala @@ -0,0 +1,5 @@ +package dotty.annotation.internal + +import scala.annotation.Annotation + +final class Repeated() extends Annotation
\ No newline at end of file diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala index 72f29fe6e..0b136d72f 100644 --- a/src/dotty/tools/dotc/Main.scala +++ b/src/dotty/tools/dotc/Main.scala @@ -9,8 +9,6 @@ import core.Contexts.Context import reporting.Reporter /* To do: -s * - Revise the way classes are inherited - when not followed by [...] or (...), - * assume the unparameterized type and forward type parameters as we do now for the synthetic head class. */ object Main extends Driver { def resident(compiler: Compiler): Reporter = unsupported("resident") /*loop { line => diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 8d891b9d9..513dee2ff 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -751,7 +751,9 @@ object desugar { makeBinop(l, op, r) case PostfixOp(t, op) => if ((ctx.mode is Mode.Type) && op == nme.raw.STAR) - AppliedTypeTree(ref(defn.RepeatedParamType), t) + Annotated( + New(ref(defn.RepeatedAnnot.typeRef), Nil :: Nil), + AppliedTypeTree(ref(defn.SeqClass.typeRef), t)) else { assert(ctx.mode.isExpr, ctx.mode) Select(t, op) diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index 8df486968..e11bdeefc 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -211,6 +211,7 @@ object Trees { */ val uniqueId = { nextId += 1 + //assert(nextId != 214, this) nextId } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index b17c40eb7..1107f184f 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -597,7 +597,7 @@ object Types { final def objToAny(implicit ctx: Context) = if ((this isRef defn.ObjectClass) && !ctx.phase.erasedTypes) defn.AnyType else this - /** If this is repeated parameter type, its underlying type, + /** If this is repeated parameter type, its underlying Seq type, * else the type itself. */ def underlyingIfRepeated(implicit ctx: Context): Type = this match { @@ -1316,7 +1316,7 @@ object Types { def withSymAndName(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef = if (prefix eq NoPrefix) withNonMemberSym(prefix, name, sym) - else if (sym.defRunId != NoRunId && sym.isCompleted) + else if (sym.defRunId != NoRunId && sym.isCompleted) withSig(prefix, name, sym.signature) withSym (sym, sym.signature) else apply(prefix, name) withSym (sym, Signature.NotAMethod) @@ -1664,9 +1664,15 @@ object Types { def apply(paramTypes: List[Type], resultType: Type)(implicit ctx: Context): MethodType = apply(nme.syntheticParamNames(paramTypes.length), paramTypes, resultType) def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = { + def paramInfo(param: Symbol): Type = param.info match { + case AnnotatedType(annot, tp) if annot matches defn.RepeatedAnnot => + tp.translateParameterized(defn.SeqClass, defn.RepeatedParamClass) + case tp => + tp + } def transformResult(mt: MethodType) = resultType.subst(params, (0 until params.length).toList map (MethodParam(mt, _))) - apply(params map (_.name.asTermName), params map (_.info))(transformResult _) + apply(params map (_.name.asTermName), params map paramInfo)(transformResult _) } } diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 12f2415d8..13f65d424 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -166,17 +166,14 @@ trait TypeAssigner { * - any further information it needs to access to compute that type. */ - def assignType(tree: untpd.Ident, rawType: Type)(implicit ctx: Context) = { - tree.withType(if (tree.isType) rawType else rawType.underlyingIfRepeated) - } + def assignType(tree: untpd.Ident, tp: Type)(implicit ctx: Context) = + tree.withType(tp) - def assignType(tree: untpd.Select, qual: Tree)(implicit ctx: Context) = { + def assignType(tree: untpd.Select, qual: Tree)(implicit ctx: Context) = tree.withType(accessibleSelectionType(tree, qual)) - } - def assignType(tree: untpd.SelectFromTypeTree, qual: Tree)(implicit ctx: Context) = { + def assignType(tree: untpd.SelectFromTypeTree, qual: Tree)(implicit ctx: Context) = tree.withType(accessibleSelectionType(tree, qual)) - } def assignType(tree: untpd.New, tpt: Tree)(implicit ctx: Context) = tree.withType(tpt.tpe) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index d46b13818..c79ecdf85 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -260,7 +260,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit error(d"not found: $kind$name", tree.pos) ErrorType } - checkValue(tree.withType(ownType.underlyingIfRepeated), pt) + checkValue(tree.withType(ownType), pt) } def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = track("typedSelect") { |