Skip to content

[WIP] Make refined type printing more source compatible #13698

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

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 18 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,24 @@ class PlainPrinter(_ctx: Context) extends Printer {

/** String representation of a refinement */
protected def toTextRefinement(rt: RefinedType): Closed =
(refinementNameString(rt) ~ toTextRHS(rt.refinedInfo)).close
println("++++++++++++++++++++++")
println(rt.parent.typeSymbol)
println(rt.refinedName)
println(rt.refinedInfo)
println("TYPE SYMBOL: " + rt.refinedInfo.typeSymbol)
println("isVar: " + rt.refinedInfo.typeSymbol.is(Mutable))
println("toSimpleName" + rt.refinedName.toSimpleName.toString)
println(rt.refinedName.toTermName)
println(rt.refinedName.toTypeName)
println(rt.parent)
println("++++++++++++++++++++++")
val keyword = rt.refinedInfo match {
case _ :TypeRef => "val "
case _: ExprType | _ : MethodType => "def "
case _: TypeBounds => "type "
case _ => ""
}
(keyword ~ refinementNameString(rt) ~ toTextRHS(rt.refinedInfo)).close

protected def argText(arg: Type): Text = homogenizeArg(arg) match {
case arg: TypeBounds => "?" ~ toText(arg)
Expand Down
4 changes: 4 additions & 0 deletions compiler/test-resources/type-printer/source-compatible
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scala> class Bag extends reflect.Selectable
// defined class Bag
scala> val m = new Bag { val f = 23; def g = 47; def h(i: Int): Int = i; var i = 101; type N = Int }
val m: Bag{val f: Int; def g: Int; def h(i: Int): Int; def i: Int; def i_=(x$1: Int): Unit; type N = Int} = anon$1@403364e9
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ScriptedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ScriptedTests extends ReplTest {

@Test def replTests = scripts("/repl").foreach(testFile)

@Test def typePrinterTests = scripts("/type-printer").foreach(testFile)
@Test def typePrinterTests = scripts("/type-printer").filter(f => f.getName == "source-compatible").foreach(testFile)
}

object ScriptedTests {
Expand Down