Skip to content

Commit

Permalink
Make sure Scala 3 dialect is used when printing instrumented code
Browse files Browse the repository at this point in the history
Previously, we would use the default dialect, which would print `import something._` instead of `import something.*` and this would break with the -source future flag that drops the former syntax.

Fixes #513
  • Loading branch information
tgodzik committed Jun 10, 2021
1 parent 38a7121 commit 3cf8e17
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class FailInstrumenter(sections: List[SectionInput], i: Int) {
) if Instrumenter.magicImports(name) =>
case importer =>
sb.print("import ")
sb.print(importer.syntax)
sb.print(importer.pos.text)
sb.print(";")
}
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Instrumenter(
case i: Import =>
def printImporter(importer: Importer): Unit = {
sb.print("import ")
sb.print(importer.syntax)
sb.print(importer.pos.text)
sb.print(";")
}
i.importers.foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class FailInstrumenter(sections: List[SectionInput], i: Int) {
case importer =>
sb.line {
_.append("import ")
.append(importer.syntax)
.append(importer.pos.text)
.append(";")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Instrumenter(
settings: Settings,
reporter: Reporter
) {
implicit val dialect: Dialect = dialects.Scala3
def instrument(): Instrumented = {
printAsScript()
Instrumented.fromSource(
Expand Down Expand Up @@ -100,7 +101,7 @@ class Instrumenter(
case i: Import =>
def printImporter(importer: Importer): Unit = {
sb.line {_.append("import ")
.append(importer.syntax)
.append(importer.pos.text)
.append(";")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ class WorksheetSuite extends BaseSuite {
|""".stripMargin
)

checkDecorations(
"import-future".tag(OnlyScala3),
"""|import $scalac.`-source future`
|import scala.collection.*
|val x = 1.to(4).toVector
|""".stripMargin,
"""|import $scalac.`-source future`
|import scala.collection.*
|<val x = 1.to(4).toVector> // : Vector[Int] = Vect...
|x: Vector[Int] = Vector(1, 2, 3, 4)
|""".stripMargin
)

checkDiagnostics(
"value-class",
"""|object Foo {
Expand Down

0 comments on commit 3cf8e17

Please sign in to comment.