Skip to content

Commit 9097a3a

Browse files
committed
Fix reflect-printing of given and erased flags
1 parent a0dcb9e commit 9097a3a

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,13 +1647,15 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
16471647
/** Intersection of the two flag sets */
16481648
def Flags_and(self: Flags)(that: Flags): Flags = self & that
16491649

1650+
def Flags_EmptyFlags: Flags = core.Flags.EmptyFlags
16501651
def Flags_Private: Flags = core.Flags.Private
16511652
def Flags_Protected: Flags = core.Flags.Protected
16521653
def Flags_Abstract: Flags = core.Flags.Abstract
16531654
def Flags_Final: Flags = core.Flags.Final
16541655
def Flags_Sealed: Flags = core.Flags.Sealed
16551656
def Flags_Case: Flags = core.Flags.Case
16561657
def Flags_Implicit: Flags = core.Flags.Implicit
1658+
def Flags_Given: Flags = core.Flags.Given
16571659
def Flags_Implied: Flags = core.Flags.Implied
16581660
def Flags_Erased: Flags = core.Flags.Erased
16591661
def Flags_Lazy: Flags = core.Flags.Lazy

library/src/scala/tasty/reflect/FlagsOps.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ trait FlagsOps extends Core {
1717

1818
object Flags {
1919

20+
/** The empty set of flags */
21+
def EmptyFlags = kernel.Flags_EmptyFlags
22+
2023
/** Is this symbol `private` */
2124
def Private: Flags = kernel.Flags_Private
2225

@@ -38,7 +41,10 @@ trait FlagsOps extends Core {
3841
/** Is this symbol `implicit` */
3942
def Implicit: Flags = kernel.Flags_Implicit
4043

41-
/** Is this symbol `erased` */
44+
/** Is this symbol an inferable ("given") parameter */
45+
def Given: Flags = kernel.Flags_Given
46+
47+
/** Is this symbol `erased` */
4248
def Erased: Flags = kernel.Flags_Erased
4349

4450
/** Is this symbol `lazy` */

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,13 +1338,15 @@ trait Kernel {
13381338
/** Intersection of the two flag sets */
13391339
def Flags_and(self: Flags)(that: Flags): Flags
13401340

1341+
def Flags_EmptyFlags: Flags
13411342
def Flags_Private: Flags
13421343
def Flags_Protected: Flags
13431344
def Flags_Abstract: Flags
13441345
def Flags_Final: Flags
13451346
def Flags_Sealed: Flags
13461347
def Flags_Case: Flags
13471348
def Flags_Implicit: Flags
1349+
def Flags_Given: Flags
13481350
def Flags_Implied: Flags
13491351
def Flags_Erased: Flags
13501352
def Flags_Lazy: Flags

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,24 +1203,30 @@ trait Printers
12031203
}
12041204
}
12051205

1206-
def printArgsDefs(args: List[ValDef])(implicit elideThis: Option[Symbol]): Unit = inParens {
1207-
args match {
1208-
case Nil =>
1209-
case arg :: _ =>
1210-
if (arg.symbol.flags.is(Flags.Erased)) this += "erased "
1211-
if (arg.symbol.flags.is(Flags.Implicit)) this += "implicit "
1206+
def printArgsDefs(args: List[ValDef])(implicit elideThis: Option[Symbol]): Unit = {
1207+
val argFlags = args match {
1208+
case Nil => Flags.EmptyFlags
1209+
case arg :: _ => arg.symbol.flags
12121210
}
1213-
1214-
def printSeparated(list: List[ValDef]): Unit = list match {
1215-
case Nil =>
1216-
case x :: Nil => printParamDef(x)
1217-
case x :: xs =>
1218-
printParamDef(x)
1219-
this += ", "
1220-
printSeparated(xs)
1211+
if (argFlags.is(Flags.Erased | Flags.Given)) {
1212+
if (argFlags.is(Flags.Given)) this += " given"
1213+
if (argFlags.is(Flags.Erased)) this += " erased"
1214+
this += " "
12211215
}
1216+
inParens {
1217+
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit "
12221218

1223-
printSeparated(args)
1219+
def printSeparated(list: List[ValDef]): Unit = list match {
1220+
case Nil =>
1221+
case x :: Nil => printParamDef(x)
1222+
case x :: xs =>
1223+
printParamDef(x)
1224+
this += ", "
1225+
printSeparated(xs)
1226+
}
1227+
1228+
printSeparated(args)
1229+
}
12241230
}
12251231

12261232
def printAnnotations(trees: List[Term])(implicit elideThis: Option[Symbol]): Buffer = {

tests/neg/erased-implicit.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ object Test {
55
def fun(implicit a: Double): Int = 42
66

77
erased implicit def doubleImplicit: Double = 42.0
8+
9+
def foo erased (implicit a: Double) = 42 // error
810
}

0 commit comments

Comments
 (0)