Skip to content

Commit 6b0e68f

Browse files
committed
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.
1 parent c16cefb commit 6b0e68f

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

docs/syntax-summary.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ grammar.
9696
ClassQualifier ::= `[' id `]'
9797

9898
Type ::= FunArgTypes `=>' Type Function(ts, t)
99-
| HkTypeParamClause `->' Type TypeLambda(ps, t)
99+
| HkTypeParamClause `=>' Type TypeLambda(ps, t)
100100
| InfixType
101101
FunArgTypes ::= InfixType
102102
| `(' [ FunArgType {`,' FunArgType } ] `)'

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,9 @@ object Parsers {
696696
else if (in.token == LBRACKET) {
697697
val start = in.offset
698698
val tparams = typeParamClause(ParamOwner.TypeParam)
699-
if (isIdent && in.name.toString == "->")
699+
if (in.token == ARROW)
700700
atPos(start, in.skipToken())(PolyTypeTree(tparams, typ()))
701-
else { syntaxErrorOrIncomplete(expectedMessage("`->'")); typ() }
701+
else { accept(ARROW); typ() }
702702
}
703703
else infixType()
704704

src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
114114
case _ => toTextGlobal(arg)
115115
}
116116

117-
/** The text for a PolyType
118-
*
119-
* [v_1 p_1: B_1, ..., v_n p_n: B_n] -> T
120-
*
121-
* where
122-
* @param paramNames = p_1, ..., p_n
123-
* @param variances = v_1, ..., v_n
124-
* @param argBoundss = B_1, ..., B_n
125-
* @param body = T
126-
*/
127-
protected def polyTypeText(paramNames: List[String], variances: List[Int], argBoundss: List[TypeBounds], body: Type): Text = {
128-
def lambdaParamText(variance: Int, name: String, bounds: TypeBounds): Text =
129-
varianceString(variance) ~ name ~ toText(bounds)
130-
changePrec(GlobalPrec) {
131-
"[" ~ Text((variances, paramNames, argBoundss).zipped.map(lambdaParamText), ", ") ~
132-
"] -> " ~ toTextGlobal(body)
133-
}
134-
}
135-
136117
/** The longest sequence of refinement types, starting at given type
137118
* and following parents.
138119
*/
@@ -186,7 +167,12 @@ class PlainPrinter(_ctx: Context) extends Printer {
186167
case tp: ExprType =>
187168
changePrec(GlobalPrec) { "=> " ~ toText(tp.resultType) }
188169
case tp: PolyType =>
189-
polyTypeText(tp.paramNames.map(_.toString), tp.variances, tp.paramBounds, tp.resultType)
170+
def paramText(variance: Int, name: Name, bounds: TypeBounds): Text =
171+
varianceString(variance) ~ name.toString ~ toText(bounds)
172+
changePrec(GlobalPrec) {
173+
"[" ~ Text((tp.variances, tp.paramNames, tp.paramBounds).zipped.map(paramText), ", ") ~
174+
"] => " ~ toTextGlobal(tp.resultType)
175+
}
190176
case tp: PolyParam =>
191177
polyParamNameString(tp) ~ polyHash(tp.binder)
192178
case AnnotatedType(tpe, annot) =>

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
2020

2121
/** A stack of enclosing DefDef, TypeDef, or ClassDef, or ModuleDefs nodes */
2222
private var enclosingDef: untpd.Tree = untpd.EmptyTree
23-
private var lambdaNestingLevel: Int = 0
2423
private var myCtx: Context = _ctx
2524
override protected[this] implicit def ctx: Context = myCtx
2625

tests/pending/pos/polytypes.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
3+
type T = [+X] => (List[X] => List[X])
4+
5+
def reverse[X](xs: List[X]): List[X] = ???
6+
7+
// val x: T = reverse
8+
9+
}

0 commit comments

Comments
 (0)