Skip to content

Commit 50d245f

Browse files
authored
Print update modifier when printing update method definitions (#23392)
I verified by printing i23389.scala with -Xprint:cc. I did not manage to make up a test case for this.
2 parents 4fa839f + 8408339 commit 50d245f

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
994994
protected def valDefToText[T <: Untyped](tree: ValDef[T]): Text = {
995995
dclTextOr(tree) {
996996
modText(tree.mods, tree.symbol, keywordStr(if (tree.mods.is(Mutable)) "var" else "val"), isType = false) ~~
997-
valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~
998-
withEnclosingDef(tree) { rhsValDef(tree) }
997+
valDefText(nameIdText(tree))
998+
~ optAscription(tree.tpt)
999+
~ withEnclosingDef(tree) { rhsValDef(tree) }
9991000
}
10001001
}
10011002

@@ -1170,6 +1171,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
11701171
if (rawFlags.is(Param)) flagMask = flagMask &~ Given
11711172
val flags = rawFlags & flagMask
11721173
var flagsText = toTextFlags(sym, flags)
1174+
if sym.isUpdateMethod then flagsText ~~= keywordStr("update")
11731175
val annotTexts =
11741176
if sym.exists then
11751177
sym.annotationsUNSAFE.filterNot(ann => dropAnnotForModText(ann.symbol)).map(toText)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import language.experimental.captureChecking
2+
import caps.*
3+
4+
package test1:
5+
6+
trait Collection[T] extends Mutable:
7+
update def add(elem: T): Unit
8+
update def remove(elem: T): Unit
9+
def get(index: Int): Option[T]
10+
11+
object Collection:
12+
def empty[T]: Collection[T] = ???
13+
14+
trait Foo:
15+
val thunks: Collection[() => Unit] // that's fine
16+
17+
object FooImpl1 extends Foo:
18+
val thunks: Collection[() => Unit] = Collection.empty // error
19+
val thunks2: Collection[() => Unit] = Collection.empty[() => Unit] // error
20+
val thunks3: Collection[() => Unit] = Collection.empty[() => Unit] // error
21+
22+
package test2:
23+
24+
trait Collection[+T] extends Mutable:
25+
def get(index: Int): Option[T]
26+
27+
object Collection:
28+
def empty[T]: Collection[T] = ???
29+
30+
trait Foo:
31+
val thunks: Collection[() => Unit] // that's fine
32+
33+
object FooImpl1 extends Foo:
34+
val thunks: Collection[() => Unit] = Collection.empty // error
35+
val thunks2: Collection[() => Unit] = Collection.empty[() => Unit] // error
36+
val thunks3: Collection[() => Unit] = Collection.empty[() => Unit] // error

0 commit comments

Comments
 (0)