Skip to content

Commit

Permalink
Merge pull request #501 from tgodzik/scala3
Browse files Browse the repository at this point in the history
Add support for Scala 3.0.0
  • Loading branch information
tgodzik committed May 14, 2021
2 parents 4b8c451 + b990d87 commit bf2b863
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
- "'++2.12.12 test'"
- "'++2.12.13 test' scripted"
- "'++2.13.5 test'"
- "'++3.0.0-RC2 test'"
- "'++3.0.0-RC3 test'"
- "'++3.0.0 test'"
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
Expand Down
1 change: 1 addition & 0 deletions bin/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ coursier fetch \
org.scalameta:mdoc_3.0.0-RC1:$version \
org.scalameta:mdoc_3.0.0-RC2:$version \
org.scalameta:mdoc_3.0.0-RC3:$version \
org.scalameta:mdoc_3.0.0:$version \
org.scalameta:mdoc-js_2.11:$version \
org.scalameta:mdoc-js_2.12.12:$version \
org.scalameta:mdoc-js_2.12:$version \
Expand Down
15 changes: 12 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scala.collection.mutable
def scala212 = "2.12.13"
def scala211 = "2.11.12"
def scala213 = "2.13.5"
def scala3 = List("3.0.0-RC3", "3.0.0-RC2", "3.0.0-RC1")
def scala3 = List("3.0.0", "3.0.0-RC3", "3.0.0-RC2", "3.0.0-RC1")
def scala2Versions = List(scala212, scala211, scala213)
def allScalaVersions = scala2Versions ::: scala3

Expand Down Expand Up @@ -113,7 +113,7 @@ lazy val sharedSettings = List(

val V = new {
val scalameta = "4.4.14"
val munit = "0.7.25"
val munit = "0.7.26"
val coursier = "1.0.3"
val scalacheck = "1.15.2"
}
Expand Down Expand Up @@ -317,9 +317,18 @@ lazy val unit = project
)
),
libraryDependencies ++= List(
"co.fs2" %% "fs2-core" % fs2Version.value,
"org.scalameta" %% "munit" % V.munit % Test
),
libraryDependencies ++= crossSetting(
scalaVersion.value,
if3 = List(
("co.fs2" %% "fs2-core" % fs2Version.value)
.cross(CrossVersion.for3Use2_13)
),
if2 = List(
"co.fs2" %% "fs2-core" % fs2Version.value
)
),
buildInfoPackage := "tests.cli",
buildInfoKeys := Seq[BuildInfoKey](
"testsInputClassDirectory" -> (testsInput / Compile / classDirectory).value
Expand Down
2 changes: 1 addition & 1 deletion mdoc/src/main/scala/mdoc/internal/markdown/Processor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object MdocDialect {
}

val scala =
if (BuildInfo.scalaBinaryVersion.startsWith("3.0"))
if (BuildInfo.scalaBinaryVersion.startsWith("3"))
Scala3.withAllowToplevelTerms(true)
else Scala213.withAllowToplevelTerms(true)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) } } }
}
}
18 changes: 18 additions & 0 deletions runtime/src/main/scala-3.0.0/mdoc/internal/sourcecode/Macros.scala
Original file line number Diff line number Diff line change
@@ -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 = v.asTerm.pos.sourceCode.getOrElse("")
'{SourceStatement[T]($v, ${Expr(txt)})}
}
}
12 changes: 2 additions & 10 deletions tests/tests/src/main/scala/tests/BaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,9 @@ class BaseSuite extends FunSuite {
val binaryVersion = tests.BuildInfo.scalaBinaryVersion
if (test.tags(OnlyScala213) && binaryVersion != "2.13")
test.tag(munit.Ignore)
else if (
test
.tags(OnlyScala3) && !(binaryVersion.startsWith("0.") || binaryVersion
.startsWith("3."))
)
else if (test.tags(OnlyScala3) && binaryVersion != "3")
test.tag(munit.Ignore)
else if (
test
.tags(SkipScala3) && (binaryVersion.startsWith("0.") || binaryVersion
.startsWith("3."))
)
else if (test.tags(SkipScala3) && binaryVersion == "3")
test.tag(munit.Ignore)
else if (test.tags(SkipScala211) && binaryVersion == "2.11")
test.tag(munit.Ignore)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class ErrorSuite extends BaseMarkdownSuite {
|^^^^^^^^^
|scala.NotImplementedError: an implementation is missing
| at scala.Predef$.$qmark$qmark$qmark(Predef.scala:347)
|""".stripMargin,
"3.0" ->
"""|error: crash.md:10:1: an implementation is missing
|x + y + z
|^^^^^^^^^
|scala.NotImplementedError: an implementation is missing
| at scala.Predef$.$qmark$qmark$qmark(Predef.scala:345)
|""".stripMargin
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,13 @@ 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),
s"""|abstract class C:
| val x: Int
|given c1 $givenSyntax
|given c1: C with
| val x = 1
|given c2 $givenSyntax
|given c2: C with
| val x = 2
|def fn(using c: C) = ()
|val xx = fn
Expand Down

0 comments on commit bf2b863

Please sign in to comment.