Skip to content

Commit 0cd1b80

Browse files
committed
Print inline and implicit in RefinedPrinter
1 parent 741958d commit 0cd1b80

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,26 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
361361
case block: Block =>
362362
blockToText(block)
363363
case If(cond, thenp, elsep) =>
364+
val isInline = tree.isInstanceOf[Trees.InlineIf[_]]
364365
changePrec(GlobalPrec) {
365-
keywordStr("if ") ~ toText(cond) ~ (keywordText(" then") provided !cond.isInstanceOf[Parens]) ~~ toText(thenp) ~ optText(elsep)(keywordStr(" else ") ~ _)
366+
keywordStr(if (isInline) "inline if " else "if ") ~
367+
toText(cond) ~ (keywordText(" then") provided !cond.isInstanceOf[Parens]) ~~
368+
toText(thenp) ~ optText(elsep)(keywordStr(" else ") ~ _)
366369
}
367370
case Closure(env, ref, target) =>
368371
"closure(" ~ (toTextGlobal(env, ", ") ~ " | " provided env.nonEmpty) ~
369372
toTextGlobal(ref) ~ (":" ~ toText(target) provided !target.isEmpty) ~ ")"
370373
case Match(sel, cases) =>
371-
if (sel.isEmpty) blockText(cases)
372-
else changePrec(GlobalPrec) { toText(sel) ~ keywordStr(" match ") ~ blockText(cases) }
374+
val isInline = tree.isInstanceOf[Trees.InlineMatch[_]]
375+
if (sel.isEmpty && !isInline) blockText(cases)
376+
else changePrec(GlobalPrec) {
377+
val selTxt: Text =
378+
if (isInline)
379+
if (sel.isEmpty) keywordStr("implicit")
380+
else keywordStr("inline ") ~ toText(sel)
381+
else toText(sel)
382+
selTxt ~ keywordStr(" match ") ~ blockText(cases)
383+
}
373384
case CaseDef(pat, guard, body) =>
374385
keywordStr("case ") ~ inPattern(toText(pat)) ~ optText(guard)(keywordStr(" if ") ~ _) ~ " => " ~ caseBlockText(body)
375386
case Labeled(bind, expr) =>

tests/invalid/run/typelevel1.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ trait HList {
44
def head: Any
55
def tail: HList
66

7-
inline def isEmpty: Boolean = length == 0
7+
inline def isEmpty <: Boolean = length == 0
88
}
99

1010
case object HNil extends HList {
11-
inline override def length = 0
11+
inline override def length <: Int = 0
1212
def head: Nothing = ???
1313
def tail: Nothing = ???
1414
}
1515

1616
case class :: [H, T <: HList] (hd: H, tl: T) extends HList {
17-
inline override def length = 1 + tl.length
18-
def head: H = this.hd
19-
def tail: T = this.tl
17+
inline override def length <: Int = 1 + tl.length
18+
inline def head: H = this.hd
19+
inline def tail: T = this.tl
2020
}
2121

2222
object Test extends App {

0 commit comments

Comments
 (0)