From d8127d2f0f31913cca7eb60a721b25974b3bfde6 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 10 Oct 2016 09:40:08 +0200 Subject: Use => instead of -> for PolyTypes If PolyTypes are to become value types we want to keep `=>` as the arrow for consistency. `->` should be reserved for PolyTypes that do not have side effects on instantiation. --- src/dotty/tools/dotc/parsing/Parsers.scala | 4 ++-- src/dotty/tools/dotc/printing/PlainPrinter.scala | 26 +++++----------------- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 1 - 3 files changed, 8 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index ab4e38638..507a2e80c 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -701,9 +701,9 @@ object Parsers { else if (in.token == LBRACKET) { val start = in.offset val tparams = typeParamClause(ParamOwner.TypeParam) - if (isIdent && in.name.toString == "->") + if (in.token == ARROW) atPos(start, in.skipToken())(PolyTypeTree(tparams, typ())) - else { syntaxErrorOrIncomplete(expectedMessage("`->'")); typ() } + else { accept(ARROW); typ() } } else infixType() diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 564ef21ef..785f57897 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -114,25 +114,6 @@ class PlainPrinter(_ctx: Context) extends Printer { case _ => toTextGlobal(arg) } - /** The text for a PolyType - * - * [v_1 p_1: B_1, ..., v_n p_n: B_n] -> T - * - * where - * @param paramNames = p_1, ..., p_n - * @param variances = v_1, ..., v_n - * @param argBoundss = B_1, ..., B_n - * @param body = T - */ - protected def polyTypeText(paramNames: List[String], variances: List[Int], argBoundss: List[TypeBounds], body: Type): Text = { - def lambdaParamText(variance: Int, name: String, bounds: TypeBounds): Text = - varianceString(variance) ~ name ~ toText(bounds) - changePrec(GlobalPrec) { - "[" ~ Text((variances, paramNames, argBoundss).zipped.map(lambdaParamText), ", ") ~ - "] -> " ~ toTextGlobal(body) - } - } - /** The longest sequence of refinement types, starting at given type * and following parents. */ @@ -186,7 +167,12 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp: ExprType => changePrec(GlobalPrec) { "=> " ~ toText(tp.resultType) } case tp: PolyType => - polyTypeText(tp.paramNames.map(_.toString), tp.variances, tp.paramBounds, tp.resultType) + def paramText(variance: Int, name: Name, bounds: TypeBounds): Text = + varianceString(variance) ~ name.toString ~ toText(bounds) + changePrec(GlobalPrec) { + "[" ~ Text((tp.variances, tp.paramNames, tp.paramBounds).zipped.map(paramText), ", ") ~ + "] => " ~ toTextGlobal(tp.resultType) + } case tp: PolyParam => polyParamNameString(tp) ~ polyHash(tp.binder) case AnnotatedType(tpe, annot) => diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index bcd12bc86..6315cfabc 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -20,7 +20,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { /** A stack of enclosing DefDef, TypeDef, or ClassDef, or ModuleDefs nodes */ private var enclosingDef: untpd.Tree = untpd.EmptyTree - private var lambdaNestingLevel: Int = 0 private var myCtx: Context = _ctx override protected[this] implicit def ctx: Context = myCtx -- cgit v1.2.3