Skip to content

fix: correctly print literal types in the refined printer #22351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case tree: TypeTree =>
typeText(toText(tree.typeOpt))
~ Str("(inf)").provided(tree.isInferred && printDebug)
case SingletonTypeTree(ref: Literal) => toTextLocal(ref)
case SingletonTypeTree(ref) =>
toTextLocal(ref) ~ "." ~ keywordStr("type")
case RefinedTypeTree(tpt, refines) =>
Expand Down
15 changes: 15 additions & 0 deletions tests/printing/i22349.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[syntax trees at end of typer]] // tests/printing/i22349.scala
package <empty> {
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
}
}

7 changes: 7 additions & 0 deletions tests/printing/i22349.scala
Original file line number Diff line number Diff line change
@@ -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
Loading