Skip to content

Commit 9b71bf9

Browse files
authored
Fix: make type pretty printer less confusing for boxed types (#906)
Fixes #659, but not #667. I propose deferring fixing #667 to a later point in time, as it requires more design. What this PR does, for now, is to parenthesize boxed types when occurring in parameter or return type positions. For example, `(Int => Int at {}) => Int` instead of `Int => Int at {} => Int`, which, in my opinion, is utterly unreadable.
1 parent 5edd555 commit 9b71bf9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

effekt/shared/src/main/scala/effekt/symbols/TypePrinter.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,17 @@ object TypePrinter extends ParenPrettyPrinter {
6666
val tps = if (tparams.isEmpty) emptyDoc else typeParams(tparams)
6767
val ps: Doc = (vparams, bparams) match {
6868
case (Nil, Nil) => "()"
69+
case (List(tpe: BoxedType), Nil) => parens(toDoc(tpe))
6970
case (List(tpe), Nil) => if (tparams.isEmpty) toDoc(tpe) else parens(toDoc(tpe))
7071
case (_, _) =>
7172
val vps = if (vparams.isEmpty) emptyDoc else parens(hsep(vparams.map(toDoc), comma))
7273
val bps = if (bparams.isEmpty) emptyDoc else hcat(bparams.map(toDoc).map(braces))
7374
vps <> bps
7475
}
75-
val ret = toDoc(result)
76+
val ret = result match {
77+
case _: BoxedType => parens(toDoc(result))
78+
case _ => toDoc(result)
79+
}
7680
val eff = if (effects.isEmpty) emptyDoc else space <> "/" <+> toDoc(effects)
7781
tps <> ps <+> "=>" <+> ret <> eff
7882

examples/neg/lambdas/inference.check

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[error] Expected type
2-
Int => Bool at {} => String
2+
(Int => Bool at {}) => String
33
but got type
4-
Int => Unit at {} => String
4+
(Int => Unit at {}) => String
55

66
Type mismatch between Bool and Unit.
77
comparing the argument types of
8-
Int => Unit at {} => String (given)
9-
Int => Bool at {} => String (expected)
8+
(Int => Unit at {}) => String (given)
9+
(Int => Bool at {}) => String (expected)
1010
when comparing the return type of the function.
1111
[error] examples/neg/lambdas/inference.effekt:13:8: Expected type
12-
Int => Bool at {} => String at {}
12+
(Int => Bool at {}) => String at {}
1313
but got type
14-
Int => Unit at {} => String at ?C
14+
(Int => Unit at {}) => String at ?C
1515

1616
Type mismatch between Bool and Unit.
1717
comparing the argument types of
18-
Int => Unit at {} => String (given)
19-
Int => Bool at {} => String (expected)
18+
(Int => Unit at {}) => String (given)
19+
(Int => Bool at {}) => String (expected)
2020
when comparing the return type of the function.
2121
hof2(fun(f: (Int) => Unit at {}) { "" })
2222
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)