Skip to content

Commit 6848fac

Browse files
committed
Print inline and implicit in RefinedPrinter
1 parent df124be commit 6848fac

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
@@ -358,15 +358,26 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
358358
case block: Block =>
359359
blockToText(block)
360360
case If(cond, thenp, elsep) =>
361+
val isInline = tree.isInstanceOf[Trees.InlineIf[_]]
361362
changePrec(GlobalPrec) {
362-
keywordStr("if ") ~ toText(cond) ~ (keywordText(" then") provided !cond.isInstanceOf[Parens]) ~~ toText(thenp) ~ optText(elsep)(keywordStr(" else ") ~ _)
363+
keywordStr(if (isInline) "inline if " else "if ") ~
364+
toText(cond) ~ (keywordText(" then") provided !cond.isInstanceOf[Parens]) ~~
365+
toText(thenp) ~ optText(elsep)(keywordStr(" else ") ~ _)
363366
}
364367
case Closure(env, ref, target) =>
365368
"closure(" ~ (toTextGlobal(env, ", ") ~ " | " provided env.nonEmpty) ~
366369
toTextGlobal(ref) ~ (":" ~ toText(target) provided !target.isEmpty) ~ ")"
367370
case Match(sel, cases) =>
368-
if (sel.isEmpty) blockText(cases)
369-
else changePrec(GlobalPrec) { toText(sel) ~ keywordStr(" match ") ~ blockText(cases) }
371+
val isInline = tree.isInstanceOf[Trees.InlineMatch[_]]
372+
if (sel.isEmpty && !isInline) blockText(cases)
373+
else changePrec(GlobalPrec) {
374+
val selTxt: Text =
375+
if (isInline)
376+
if (sel.isEmpty) keywordStr("implicit")
377+
else keywordStr("inline ") ~ toText(sel)
378+
else toText(sel)
379+
selTxt ~ keywordStr(" match ") ~ blockText(cases)
380+
}
370381
case CaseDef(pat, guard, body) =>
371382
keywordStr("case ") ~ inPattern(toText(pat)) ~ optText(guard)(keywordStr(" if ") ~ _) ~ " => " ~ caseBlockText(body)
372383
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)