From 92f177aac9d8bbaf8705c05c197b0ea03de37f68 Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Sun, 12 Jan 2025 22:43:35 +0100 Subject: [PATCH 1/2] fix: correctly print litteral types in the refined printer --- .../tools/dotc/printing/RefinedPrinter.scala | 1 + tests/printing/i22349.check | 15 +++++++++++++++ tests/printing/i22349.scala | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/printing/i22349.check create mode 100644 tests/printing/i22349.scala diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index f70a4ffef914..4fdfd7cb3e60 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -540,6 +540,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case TypeTree() => typeText(toText(tree.typeOpt)) ~ Str("(inf)").provided(tree.isInstanceOf[InferredTypeTree] && printDebug) + case SingletonTypeTree(ref: Literal) => toTextLocal(ref) case SingletonTypeTree(ref) => toTextLocal(ref) ~ "." ~ keywordStr("type") case RefinedTypeTree(tpt, refines) => diff --git a/tests/printing/i22349.check b/tests/printing/i22349.check new file mode 100644 index 000000000000..7869f5f7fc4f --- /dev/null +++ b/tests/printing/i22349.check @@ -0,0 +1,15 @@ +[[syntax trees at end of typer]] // tests/printing/i22349.scala +package { + final lazy module val i22349$package: i22349$package = new i22349$package() + final module class i22349$package() extends Object() { + this: i22349$package.type => + val x: Int = 0 + val _$1: x.type = x + inline val _$2: true = true + inline val _$3: "abc" = "abc" + inline val _$4: 'c' = 'c' + inline val _$5: 1.2f = 1.2f + inline val _$6: 1.2d = 1.2d + } +} + diff --git a/tests/printing/i22349.scala b/tests/printing/i22349.scala new file mode 100644 index 000000000000..33122f0b91e8 --- /dev/null +++ b/tests/printing/i22349.scala @@ -0,0 +1,7 @@ +val x = 0 +val _: x.type = x +inline val _: true = true // boolean literal +inline val _: "abc" = "abc" // string literal +inline val _: 'c' = 'c' // character literal +inline val _: 1.2f = 1.2f // floating point literal +inline val _: 1.2d = 1.2d // double number literal From f6a858e094f992497b0bcaaf6198a49d28c7c6ca Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 14 Mar 2025 19:22:22 +0100 Subject: [PATCH 2/2] fix: correctly print litteral types in the refined printer [Cherry-picked 937bc4ceb323185433da8b773ddb92c491a319a1][modified]