Skip to content

Commit dc4c10f

Browse files
committed
Improve presentation compiler fixes
1 parent b51acda commit dc4c10f

10 files changed

Lines changed: 30 additions & 17 deletions

File tree

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ private sealed trait YSettings:
483483
val YexplainLowlevel: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
484484
val YnoDoubleBindings: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-double-bindings", "Assert no namedtype is bound twice (should be enabled only if program is error-free).")
485485
val YshowVarBounds: Setting[Boolean] = BooleanSetting(ForkSetting, "Yshow-var-bounds", "Print type variables with their bounds.")
486+
val YhideFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yhide-flexible-types", "Print flexible types as their base type. (T instead of (T)?)")
486487

487488
val Yinstrument: Setting[Boolean] = BooleanSetting(ForkSetting, "Yinstrument", "Add instrumentation code that counts allocations and closure creations.")
488489
val YinstrumentDefs: Setting[Boolean] = BooleanSetting(ForkSetting, "Yinstrument-defs", "Add instrumentation code that counts method calls; needs -Yinstrument to be set, too.")

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
336336
case _ =>
337337
toTextLocal(tpe) ~ " " ~ toText(annot)
338338
case FlexibleType(_, tpe) =>
339-
"(" ~ toText(tpe) ~ ")?"
339+
if (ctx.settings.YhideFlexibleTypes.value) then
340+
toText(tpe)
341+
else
342+
"(" ~ toText(tpe) ~ ")?"
340343
case tp: TypeVar =>
341344
def toTextCaret(tp: Type) = if printDebug then toTextLocal(tp) ~ Str("^") else toText(tp)
342345
if (tp.isInstantiated)

presentation-compiler/src/main/dotty/tools/pc/InferredMethodProvider.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ final class InferredMethodProvider(
6868
Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
6969

7070
given locatedCtx: Context = driver.localContext(params)
71-
val indexedCtx = IndexedContext(pos)(using locatedCtx)
71+
val locatedCtx2 = locatedCtx.fresh.setSettings(ctx.settings.YhideFlexibleTypes.updateIn(
72+
ctx.settingsState.reinitializedCopy(),
73+
true
74+
))
75+
val indexedCtx = IndexedContext(pos)(using locatedCtx2)
7276

7377
val autoImportsGen = AutoImports.generator(
7478
pos,

presentation-compiler/src/main/dotty/tools/pc/InferredTypeProvider.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ final class InferredTypeProvider(
7575
Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
7676

7777
given locatedCtx: Context = driver.localContext(params)
78-
val indexedCtx = IndexedContext(pos)(using locatedCtx)
78+
val locatedCtx2 = locatedCtx.fresh.setSettings(ctx.settings.YhideFlexibleTypes.updateIn(
79+
ctx.settingsState.reinitializedCopy(),
80+
true
81+
))
82+
val indexedCtx = IndexedContext(pos)(using locatedCtx2)
7983
val autoImportsGen = AutoImports.generator(
8084
pos,
8185
sourceText,

presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CompletionProvider(
8282
case Some(unit) =>
8383
val newctx = ctx.fresh
8484
.setCompilationUnit(unit)
85+
.setSettings(ctx.settings.YhideFlexibleTypes.updateIn(ctx.settingsState.reinitializedCopy(), true))
8586
.setProfiler(Profiler()(using ctx))
8687
.withPhase(Phases.typerPhase(using ctx))
8788
val tpdPath0 = Interactive.pathTo(unit.tpdTree, pos.span)(using newctx)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionDocSuite.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class CompletionDocSuite extends BaseCompletionSuite:
6262
| "".substrin@@
6363
|}
6464
""".stripMargin,
65-
"""|substring(beginIndex: Int): (String)?
66-
|substring(beginIndex: Int, endIndex: Int): (String)?
65+
"""|substring(beginIndex: Int): String
66+
|substring(beginIndex: Int, endIndex: Int): String
6767
|""".stripMargin
6868
)
6969

@@ -74,7 +74,7 @@ class CompletionDocSuite extends BaseCompletionSuite:
7474
| String.join@@
7575
|}
7676
""".stripMargin,
77-
"""|join(delimiter: (CharSequence)?, elements: ((CharSequence)?*)?): (String)?
77+
"""|join(delimiter: CharSequence, elements: CharSequence*): String
7878
|""".stripMargin,
7979
topLines = Some(1)
8080
)
@@ -89,7 +89,7 @@ class CompletionDocSuite extends BaseCompletionSuite:
8989
| }
9090
|}
9191
""".stripMargin,
92-
"""|setValue(value: (Int)?): (Int)?
92+
"""|setValue(value: Int): Int
9393
|""".stripMargin
9494
)
9595

@@ -100,7 +100,7 @@ class CompletionDocSuite extends BaseCompletionSuite:
100100
| java.util.Collections.singletonLis@@
101101
|}
102102
""".stripMargin,
103-
"""|singletonList[T](o: (T)?): (java.util.List[T])?
103+
"""|singletonList[T](o: T): java.util.List[T]
104104
|""".stripMargin
105105
)
106106

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class CompletionOverrideSuite extends BaseCompletionSuite:
133133
|
134134
|object Main {
135135
| new java.nio.file.SimpleFileVisitor[java.nio.file.Path] {
136-
| override def visitFile(file: (Path)?, attrs: (BasicFileAttributes)?): (FileVisitResult)? = ${0:???}
136+
| override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = ${0:???}
137137
| }
138138
|}
139139
|""".stripMargin,

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class CompletionSuite extends BaseCompletionSuite:
469469
| new java.util.ArrayList[String]().forEach(p => p.toChar@@)
470470
|}
471471
""".stripMargin,
472-
"""|toCharArray(): (Array[Char])?
472+
"""|toCharArray(): Array[Char]
473473
|""".stripMargin
474474
)
475475

@@ -505,8 +505,8 @@ class CompletionSuite extends BaseCompletionSuite:
505505
| java.nio.file.Files.readAttributes@@
506506
|}
507507
""".stripMargin,
508-
"""|readAttributes(path: (Path)?, attributes: (String)?, options: ((LinkOption)?*)?): (java.util.Map[String, Object])?
509-
|readAttributes[A <: BasicFileAttributes](path: (Path)?, type: (Class[A])?, options: ((LinkOption)?*)?): (A)?
508+
"""|readAttributes(path: Path, attributes: String, options: LinkOption*): java.util.Map[String, Object]
509+
|readAttributes[A <: BasicFileAttributes](path: Path, type: Class[A], options: LinkOption*): A
510510
|""".stripMargin
511511
)
512512

@@ -841,8 +841,8 @@ class CompletionSuite extends BaseCompletionSuite:
841841
| "".substring@@
842842
|}
843843
|""".stripMargin,
844-
"""substring(beginIndex: Int): (String)?
845-
|substring(beginIndex: Int, endIndex: Int): (String)?
844+
"""substring(beginIndex: Int): String
845+
|substring(beginIndex: Int, endIndex: Int): String
846846
|""".stripMargin,
847847
filterText = "substring"
848848
)

presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredMethodSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class InsertInferredMethodSuite extends BaseCodeActionSuite:
220220
| def main() = {
221221
| def method1(s : String) = 123
222222
| val path = Files.createTempDirectory("")
223-
| def otherMethod(arg0: (Path)?): String = ???
223+
| def otherMethod(arg0: Path): String = ???
224224
| method1(otherMethod(path))
225225
| }
226226
|}
@@ -550,7 +550,7 @@ class InsertInferredMethodSuite extends BaseCodeActionSuite:
550550
|
551551
|object Main:
552552
| val p = Paths.get("test")
553-
| extension (x: (Path)?)
553+
| extension (x: Path)
554554
| def newMethod = ???
555555
| p.newMethod
556556
|""".stripMargin

presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class InsertInferredTypeSuite extends BaseCodeActionSuite:
467467
| object inner {
468468
| val nio: java.nio.file.Path = path
469469
| object inner {
470-
| val java: (_root_.java.nio.file.Path)? = path
470+
| val java: _root_.java.nio.file.Path = path
471471
| }
472472
| }
473473
| }

0 commit comments

Comments
 (0)