diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a780bc064..becef2d9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: - "'++2.12.12 test' scripted" - "'++2.13.4 test'" - "'++3.0.0-M2 test'" + - "'++3.0.0-M3 test'" steps: - uses: actions/checkout@v2 - uses: olafurpg/setup-scala@v10 diff --git a/bin/test-release.sh b/bin/test-release.sh index a301d2f7c..3573d6333 100755 --- a/bin/test-release.sh +++ b/bin/test-release.sh @@ -9,7 +9,8 @@ coursier fetch \ org.scalameta:mdoc_2.11:$version \ org.scalameta:mdoc_2.12:$version \ org.scalameta:mdoc_2.13:$version \ - org.scalameta:mdoc_3.0.0-M1:$version \ + org.scalameta:mdoc_3.0.0-M2:$version \ + org.scalameta:mdoc_3.0.0-M3:$version \ org.scalameta:mdoc-js_2.11:$version \ org.scalameta:mdoc-js_2.12:$version \ org.scalameta:mdoc-js_2.13:$version $suffix diff --git a/build.sbt b/build.sbt index 4780fab93..2b2080554 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ import scala.collection.mutable def scala212 = "2.12.12" def scala211 = "2.11.12" def scala213 = "2.13.4" -def scala3 = List("3.0.0-M2") +def scala3 = List("3.0.0-M3", "3.0.0-M2") def scalajs = "1.3.0" def scalajsBinaryVersion = "1" @@ -12,8 +12,7 @@ def scalajsDom = "1.1.0" def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) def isScala212(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 12) def isScala211(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 11) -def isScala3(v: Option[(Long, Long)]): Boolean = - v.exists(_._1 == 0) || v.exists(_._1 == 3) +def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3) val isScala213 = Def.setting { VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector(">=2.13")) @@ -110,7 +109,7 @@ lazy val sharedSettings = List( val V = new { val scalameta = "4.4.0" - val munit = "0.7.19" + val munit = "0.7.20" val coursier = "1.0.2" val scalacheck = "1.15.1" } diff --git a/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala b/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala index 4747f55f4..e5a7a909c 100644 --- a/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala +++ b/mdoc/src/main/scala-3/mdoc/internal/markdown/Instrumenter.scala @@ -62,8 +62,8 @@ class Instrumenter( printlnWithIndent("") printlnWithIndent("$doc.startSection();") section.stats.foreach { stat => - printlnWithIndent(s"$$doc.startStatement(${position(stat.sourcePos)});") - printStatement(stat, section.mod, sb, section) + printlnWithIndent(s"$$doc.startStatement(${position(stat.sourcePos(using ctx))});") + printStatement(stat, section.mod, sb, section)(using ctx) printlnWithIndent("") printlnWithIndent("$doc.endStatement();") } diff --git a/mdoc/src/main/scala-3/mdoc/internal/markdown/SectionInput.scala b/mdoc/src/main/scala-3/mdoc/internal/markdown/SectionInput.scala index c14cdd252..ea820d2d4 100644 --- a/mdoc/src/main/scala-3/mdoc/internal/markdown/SectionInput.scala +++ b/mdoc/src/main/scala-3/mdoc/internal/markdown/SectionInput.scala @@ -30,7 +30,7 @@ case class SectionInput(input : Input, mod : Modifier, context : MContext){ private val filename = "Section.scala" driver.run(java.net.URI.create("file:///Section.scala"), SourceFile.virtual(filename, sourceCode)) val source = driver.currentCtx.run.units.head.untpdTree - given ctx as Context = driver.currentCtx + val ctx = driver.currentCtx def stats : List[Tree] = { source match { case PackageDef(_, List(module @ _ : ModuleDef)) => @@ -40,8 +40,8 @@ case class SectionInput(input : Input, mod : Modifier, context : MContext){ } def show(tree : Tree, currentIdent : Int) = { - val str = tree.sourcePos.start - val end = tree.sourcePos.end + val str = tree.sourcePos(using ctx).start + val end = tree.sourcePos(using ctx).end // workaround should be removed once support for 0.26.0 is dropped val prefix = if (BuildInfo.scalaBinaryVersion == "0.26") tree match { diff --git a/runtime/src/main/scala-3.0.0-M2/pprint/SourceTypePrinter.scala b/runtime/src/main/scala-3.0.0-M2/mdoc/internal/pprint/SourceTypePrinter.scala similarity index 100% rename from runtime/src/main/scala-3.0.0-M2/pprint/SourceTypePrinter.scala rename to runtime/src/main/scala-3.0.0-M2/mdoc/internal/pprint/SourceTypePrinter.scala diff --git a/runtime/src/main/scala-3.0.0-M2/pprint/TypePrinter.scala b/runtime/src/main/scala-3.0.0-M2/mdoc/internal/pprint/TypePrinter.scala similarity index 100% rename from runtime/src/main/scala-3.0.0-M2/pprint/TypePrinter.scala rename to runtime/src/main/scala-3.0.0-M2/mdoc/internal/pprint/TypePrinter.scala diff --git a/runtime/src/main/scala-3/mdoc/internal/sourcecode/Macros.scala b/runtime/src/main/scala-3.0.0-M2/mdoc/internal/sourcecode/Macros.scala similarity index 100% rename from runtime/src/main/scala-3/mdoc/internal/sourcecode/Macros.scala rename to runtime/src/main/scala-3.0.0-M2/mdoc/internal/sourcecode/Macros.scala diff --git a/runtime/src/main/scala-3.0.0-M3/mdoc/internal/pprint/TypePrinter.scala b/runtime/src/main/scala-3.0.0-M3/mdoc/internal/pprint/TypePrinter.scala new file mode 100644 index 000000000..13c2c7029 --- /dev/null +++ b/runtime/src/main/scala-3.0.0-M3/mdoc/internal/pprint/TypePrinter.scala @@ -0,0 +1,24 @@ +package mdoc.internal.pprint + +import scala.language.implicitConversions +import scala.quoted._ +import scala.quoted.runtime.impl.printers.SyntaxHighlight + +trait TPrint[T]{ + def render: String +} + +object TPrint { + inline given default[T]: TPrint[T] = ${ TypePrinter.typeString[T] } +} + +object TypePrinter{ + + def typeString[T](using ctx: Quotes, tpe: Type[T]): Expr[TPrint[T]] = { + import ctx.reflect._ + + val valueType = TypeTree.of[T](using tpe).tpe.show(using Printer.TypeReprShortCode) + + '{ new TPrint[T]{ def render: String = ${ Expr(valueType) } } } + } +} diff --git a/runtime/src/main/scala-3.0.0-M3/mdoc/internal/sourcecode/Macros.scala b/runtime/src/main/scala-3.0.0-M3/mdoc/internal/sourcecode/Macros.scala new file mode 100644 index 000000000..b16bfb1f1 --- /dev/null +++ b/runtime/src/main/scala-3.0.0-M3/mdoc/internal/sourcecode/Macros.scala @@ -0,0 +1,18 @@ +package mdoc.internal.sourcecode + +import scala.language.implicitConversions +import scala.quoted._ + +trait StatementMacro { + inline implicit def generate[T](v: => T): SourceStatement[T] = ${ Macros.text('v) } + inline def apply[T](v: => T): SourceStatement[T] = ${ Macros.text('v) } +} + +object Macros{ + + def text[T: Type](v: Expr[T])(using ctx: Quotes): Expr[SourceStatement[T]] = { + import ctx.reflect.{_, given} + val txt = Term.of(v).pos.sourceCode.getOrElse("") + '{SourceStatement[T]($v, ${Expr(txt)})} + } +} \ No newline at end of file diff --git a/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala b/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala index 16eb92429..938bcffe4 100644 --- a/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala +++ b/tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala @@ -330,17 +330,18 @@ class WorksheetSuite extends BaseSuite { |""".stripMargin ) + val givenSyntax = if (tests.BuildInfo.scalaVersion == "3.0.0-M2") "as C:" else ": C with" checkDiagnostics( "dotty-ambiguous-implicit".tag(OnlyScala3), - """|abstract class C: - | val x: Int - |given c1 as C: - | val x = 1 - |given c2 as C: - | val x = 2 - |def fn(using c: C) = () - |val xx = fn - |""".stripMargin, + s"""|abstract class C: + | val x: Int + |given c1 $givenSyntax + | val x = 1 + |given c2 $givenSyntax + | val x = 2 + |def fn(using c: C) = () + |val xx = fn + |""".stripMargin, """|dotty-ambiguous-implicit:8:10: error: ambiguous implicit arguments: both object c1 in class App and object c2 in class App match type App.this.C of parameter c of method fn in class App |val xx = fn | ^^