Skip to content

Commit

Permalink
Merge pull request #432 from tgodzik/update-3.0.0-M3
Browse files Browse the repository at this point in the history
Add support for Scala 3.0.0-M3
  • Loading branch information
tgodzik authored Dec 17, 2020
2 parents b95d7be + 1de43b8 commit c0e6315
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bin/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 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.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"
Expand All @@ -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"))
Expand Down Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) =>
Expand All @@ -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 {
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) } } }
}
}
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 = Term.of(v).pos.sourceCode.getOrElse("")
'{SourceStatement[T]($v, ${Expr(txt)})}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
| ^^
Expand Down

0 comments on commit c0e6315

Please sign in to comment.