Skip to content

Commit 37ca1ee

Browse files
committed
Fix printing private and protected modifiers
1 parent c5d3b67 commit 37ca1ee

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,28 +1368,24 @@ object SourceCode {
13681368

13691369
private def printProtectedOrPrivate(definition: Definition): Boolean = {
13701370
var prefixWasPrinted = false
1371-
def printWithin(within: TypeRepr) = within match {
1372-
case TypeRef(_, name) => this += name
1373-
case _ => printFullClassName(within)
1374-
}
1375-
if (definition.symbol.flags.is(Flags.Protected)) {
1371+
def printWithin(within: Option[TypeRepr]) = within match
1372+
case _ if definition.symbol.flags.is(Flags.Local) => inSquare(this += "this")
1373+
case Some(TypeRef(_, name)) => inSquare(this += name)
1374+
case Some(within) => inSquare(printFullClassName(within))
1375+
case _ =>
1376+
1377+
if definition.symbol.flags.is(Flags.Protected) then
13761378
this += highlightKeyword("protected")
1377-
definition.symbol.protectedWithin match {
1378-
case Some(within) =>
1379-
inSquare(printWithin(within))
1380-
case _ =>
1381-
}
1379+
printWithin(definition.symbol.protectedWithin)
13821380
prefixWasPrinted = true
1383-
} else {
1384-
definition.symbol.privateWithin match {
1385-
case Some(within) =>
1386-
this += highlightKeyword("private")
1387-
inSquare(printWithin(within))
1388-
prefixWasPrinted = true
1389-
case _ =>
1390-
}
1391-
}
1392-
if (prefixWasPrinted)
1381+
else
1382+
val privateWithin = definition.symbol.privateWithin
1383+
if privateWithin.isDefined || definition.symbol.flags.is(Flags.Private) then
1384+
this += highlightKeyword("private")
1385+
printWithin(definition.symbol.privateWithin)
1386+
prefixWasPrinted = true
1387+
1388+
if prefixWasPrinted then
13931389
this += " "
13941390
prefixWasPrinted
13951391
}

0 commit comments

Comments
 (0)