Skip to content

Commit

Permalink
Fix printing of reach capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 8, 2024
1 parent 7e7b3f9 commit d06a5e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
homogenize(tp) match
case tp: TermRef if tp.symbol == defn.captureRoot => Str("cap")
case tp: SingletonType => toTextRef(tp)
case ReachCapability(tp1) => toTextRef(tp1) ~ "*"
case MaybeCapability(tp1) => toTextRef(tp1) ~ "?"
case tp: (TypeRef | TypeParamRef) => toText(tp) ~ "^"
case _ => toText(tp)
case tp: AnnotatedType if tp.isReach => toTextCaptureRef(tp.stripReach) ~ "*"
case tp: AnnotatedType if tp.isMaybe => toTextCaptureRef(tp.stripMaybe) ~ "?"
case tp => toText(tp)

protected def isOmittablePrefix(sym: Symbol): Boolean =
defn.unqualifiedOwnerTypes.exists(_.symbol == sym) || isEmptyPrefix(sym)
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
"?" ~ (("(ignored: " ~ toText(ignored) ~ ")") provided printDebug)
case tp @ PolyProto(targs, resType) =>
"[applied to [" ~ toTextGlobal(targs, ", ") ~ "] returning " ~ toText(resType)
case tp: AnnotatedType if tp.isReach || tp.isMaybe =>
toTextCaptureRef(tp)
case _ =>
super.toText(tp)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/neg-custom-args/captures/reaches2.check
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Error: tests/neg-custom-args/captures/reaches2.scala:8:10 -----------------------------------------------------------
8 | ps.map((x, y) => compose1(x, y)) // error // error
| ^
|reference (ps : List[(box A => A, box A => A)]) @reachCapability is not included in the allowed capture set {}
|reference ps* is not included in the allowed capture set {}
|of an enclosing function literal with expected type ((box A ->{ps*} A, box A ->{ps*} A)) -> box (x$0: A^?) ->? (ex$15: caps.Exists) -> A^?
-- Error: tests/neg-custom-args/captures/reaches2.scala:8:13 -----------------------------------------------------------
8 | ps.map((x, y) => compose1(x, y)) // error // error
| ^
|reference (ps : List[(box A => A, box A => A)]) @reachCapability is not included in the allowed capture set {}
|reference ps* is not included in the allowed capture set {}
|of an enclosing function literal with expected type ((box A ->{ps*} A, box A ->{ps*} A)) -> box (x$0: A^?) ->? (ex$15: caps.Exists) -> A^?

0 comments on commit d06a5e6

Please sign in to comment.