Skip to content

Commit 8c143d0

Browse files
committed
Merge branch 'update-dotty-macros' of https://github.com/dotty-staging/scalatest into dotty-fix-20190731
2 parents 90e98b8 + ba9da00 commit 8c143d0

21 files changed

+184
-200
lines changed

common-test.dotty/src/main/scala/org/scalatest/LineNumberHelper.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ private[scalatest] trait LineNumberHelper {
88
}
99

1010
object LineNumberMacro {
11-
def thisLineNumberImpl(implicit refl: Reflection): Expr[Int] = {
12-
import refl._
13-
14-
refl.rootPosition.startLine.toExpr
11+
def thisLineNumberImpl(implicit qctx: QuoteContext): Expr[Int] = {
12+
import qctx.tasty._
13+
rootPosition.startLine.toExpr
1514
}
1615
}

project/GenAnyVals.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ object GenAnyVals {
2929
val macroCode =
3030
if (dotty)
3131
s"""
32-
| def apply(value: Expr[$primitiveTypeName])(implicit refl: Reflection): Expr[$typeName] = {
32+
| def apply(value: Expr[$primitiveTypeName])(implicit qctx: QuoteContext): Expr[$typeName] = {
3333
| val notValidMsg = Resources.notValid$typeName
3434
| val notLiteralMsg = Resources.notLiteral$typeName
35-
| import refl._
35+
| import qctx.tasty._
3636
| ensureValid${primitiveTypeName}Literal(value, notValidMsg, notLiteralMsg)(isValid)
3737
| '{ $typeName.ensuringValid($$value) }
3838
| }
@@ -650,9 +650,7 @@ object GenAnyVals {
650650

651651
def importsForMacro(dotty: Boolean): String =
652652
if (dotty)
653-
"""import scala.quoted._
654-
|import scala.tasty._
655-
""".stripMargin
653+
"import scala.quoted._"
656654
else
657655
"import reflect.macros.Context"
658656

project/GenFactoriesDotty.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,6 @@ object MatcherFactory$arity$ {
28682868
28692869
import scala.language.implicitConversions
28702870
import scala.quoted._
2871-
import scala.tasty._
28722871
28732872
/**
28742873
* Converts a <code>MatcherFactory$arity$</code> to a <code>Matcher</code>.
@@ -2882,7 +2881,7 @@ object MatcherFactory$arity$ {
28822881
/**
28832882
* This method is called by macro that supports 'and not a [Type]' syntax.
28842883
*/
2885-
def andNotATypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#AndNotWord], aType: Expr[ResultOfATypeInvocation[_]])(implicit refl: Reflection, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
2884+
def andNotATypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#AndNotWord], aType: Expr[ResultOfATypeInvocation[_]])(implicit qctx: QuoteContext, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
28862885
val rhs = TypeMatcherMacro.notATypeMatcher(aType)
28872886
28882887
'{ (\$self).owner.and(\$rhs) }
@@ -2891,33 +2890,33 @@ object MatcherFactory$arity$ {
28912890
/**
28922891
* This method is called by macro that supports 'or not a [Type]' syntax.
28932892
*/
2894-
def orNotATypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#OrNotWord], aType: Expr[ResultOfATypeInvocation[_]])(implicit refl: Reflection, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
2893+
def orNotATypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#OrNotWord], aType: Expr[ResultOfATypeInvocation[_]])(implicit qctx: QuoteContext, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
28952894
val rhs = TypeMatcherMacro.notATypeMatcher(aType)
28962895
'{ (\$self).owner.or(\$rhs) }
28972896
}
28982897
28992898
/**
29002899
* This method is called by macro that supports 'and not a [Type]' syntax.
29012900
*/
2902-
def andNotAnTypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#AndNotWord], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit refl: Reflection, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
2901+
def andNotAnTypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#AndNotWord], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit qctx: QuoteContext, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
29032902
val rhs = TypeMatcherMacro.notAnTypeMatcher(anType)
29042903
'{ (\$self).owner.and(\$rhs) }
29052904
}
29062905
29072906
/**
29082907
* This method is called by macro that supports 'or not a [Type]' syntax.
29092908
*/
2910-
def orNotAnTypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#OrNotWord], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit refl: Reflection, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
2909+
def orNotAnTypeMatcherFactory$arity$[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#OrNotWord], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit qctx: QuoteContext, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
29112910
val rhs = TypeMatcherMacro.notAnTypeMatcher(anType)
29122911
'{ (\$self).owner.or(\$rhs) }
29132912
}
29142913
2915-
def andNotMatchPattern[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#AndNotWord], right: Expr[PartialFunction[Any, _]])(implicit refl: Reflection, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
2914+
def andNotMatchPattern[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#AndNotWord], right: Expr[PartialFunction[Any, _]])(implicit qctx: QuoteContext, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
29162915
val notMatcher = '{ MatchPatternHelper.notMatchPatternMatcher(\$right) }
29172916
'{ (\$self).owner.and(\$notMatcher) }
29182917
}
29192918
2920-
def orNotMatchPattern[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#OrNotWord], right: Expr[PartialFunction[Any, _]])(implicit refl: Reflection, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
2919+
def orNotMatchPattern[SC: Type, $typeConstructors$](self: Expr[MatcherFactory$arity$[SC & AnyRef, $commaSeparatedTCNs$]#OrNotWord], right: Expr[PartialFunction[Any, _]])(implicit qctx: QuoteContext, $typeConstructorsWithType$): Expr[MatcherFactory$arity$[SC with AnyRef, $commaSeparatedTCNs$]] = {
29212920
val notMatcher = '{ MatchPatternHelper.notMatchPatternMatcher(\$right) }
29222921
'{ (\$self).owner.or(\$notMatcher) }
29232922
}

project/scalatest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,8 +2219,8 @@ object ScalatestBuild {
22192219
name.value)
22202220

22212221
// List of available night build at https://repo1.maven.org/maven2/ch/epfl/lamp/dotty-compiler_0.14/
2222-
lazy val dottyVersion = dottyLatestNightlyBuild.get
2223-
// lazy val dottyVersion = "0.15.0-bin-20190522-ffb250d-NIGHTLY"
2222+
// lazy val dottyVersion = dottyLatestNightlyBuild.get
2223+
lazy val dottyVersion = "0.17.0-RC1"
22242224
lazy val dottySettings = List(
22252225
scalaVersion := dottyVersion,
22262226
libraryDependencies := libraryDependencies.value.map(_.withDottyCompat(scalaVersion.value)),

scalactic.dotty/src/main/scala/org/scalactic/BooleanMacro.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.scalactic
1717

1818
import scala.quoted._
19-
import scala.tasty._
2019

2120
object BooleanMacro {
2221
private val logicOperators = Set("&&", "||", "&", "|")
@@ -38,11 +37,11 @@ object BooleanMacro {
3837
"ne",
3938
"exists") ++ logicOperators
4039

41-
def parse(condition: Expr[Boolean], prettifier: Expr[Prettifier])(implicit refl: Reflection): Expr[Bool] = {
42-
import refl._
40+
def parse(condition: Expr[Boolean], prettifier: Expr[Prettifier])(implicit qctx: QuoteContext): Expr[Bool] = {
41+
import qctx.tasty._
4342
import util._
4443

45-
def exprStr: String = condition.show(the[Context].withoutColors)
44+
def exprStr: String = condition.show
4645
def defaultCase = '{ Bool.simpleMacroBool($condition, ${exprStr.toExpr}, $prettifier) }
4746
def isImplicitMethodType(tp: Type): Boolean =
4847
Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
@@ -229,7 +228,7 @@ object BooleanMacro {
229228
case TypeApply(sel @ Select(lhs, "isInstanceOf"), targs) =>
230229
let(lhs) { l =>
231230
val res = l.select(sel.symbol).appliedToTypeTrees(targs).seal.cast[Boolean]
232-
val name = targs.head.tpe.show(the[Context].withoutColors).toExpr
231+
val name = targs.head.tpe.show.toExpr
233232
'{ Bool.isInstanceOfMacroBool(${l.seal}, "isInstanceOf", $name, $res, $prettifier) }.unseal
234233
}.seal.cast[Bool]
235234

scalactic.dotty/src/main/scala/org/scalactic/Requirements.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package org.scalactic
1818
import exceptions.NullArgumentException
1919

2020
import scala.quoted._
21-
import scala.tasty._
2221

2322
/**
2423
* Trait that contains <code>require</code>, and <code>requireState</code>, and <code>requireNonNull</code> methods for checking pre-conditions
@@ -231,8 +230,8 @@ object RequirementsMacro {
231230
* @param condition original condition expression
232231
* @return transformed expression that performs the requirement check and throw <code>IllegalArgumentException</code> with rich error message if requirement failed
233232
*/
234-
def require(condition: Expr[Boolean], prettifier: Expr[Prettifier], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
235-
import refl._
233+
def require(condition: Expr[Boolean], prettifier: Expr[Prettifier], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Unit] = {
234+
import qctx.tasty._
236235

237236
val bool = BooleanMacro.parse(condition, prettifier)
238237
'{ Requirements.requirementsHelper.macroRequire($bool, $clue) }
@@ -245,8 +244,8 @@ object RequirementsMacro {
245244
* @param condition original condition expression
246245
* @return transformed expression that performs the requirement check and throw <code>IllegalStateException</code> with rich error message if requirement failed
247246
*/
248-
def requireState(condition: Expr[Boolean], prettifier: Expr[Prettifier], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
249-
import refl._
247+
def requireState(condition: Expr[Boolean], prettifier: Expr[Prettifier], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Unit] = {
248+
import qctx.tasty._
250249

251250
val bool = BooleanMacro.parse(condition, prettifier)
252251
'{ Requirements.requirementsHelper.macroRequireState($bool, $clue) }
@@ -259,8 +258,8 @@ object RequirementsMacro {
259258
* @param prettifier <code>Prettifier</code> to be used for error message
260259
* @return transformed expression that performs the requirement check and throw <code>NullArgumentException</code> with rich error message if requirement failed
261260
*/
262-
def requireNonNull(arguments: Expr[Seq[Any]], prettifier: Expr[Prettifier], pos: Expr[source.Position])(implicit reflect: Reflection): Expr[Unit] = {
263-
import reflect._
261+
def requireNonNull(arguments: Expr[Seq[Any]], prettifier: Expr[Prettifier], pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Unit] = {
262+
import qctx.tasty._
264263

265264
def liftSeq(args: Seq[Expr[String]]): Expr[Seq[String]] = args match {
266265
case x :: xs => '{ ($x) +: ${ liftSeq(xs) } }
@@ -269,9 +268,10 @@ object RequirementsMacro {
269268

270269
val argStr: List[Expr[String]] = arguments.unseal.underlyingArgument match {
271270
case Typed(Repeated(args, _), _) => // only sequence literal
272-
args.map(arg => arg.seal.cast[Any].show(the[Context].withoutColors).toExpr)
271+
args.map(arg => arg.seal.cast[Any].show.toExpr)
273272
case _ =>
274-
throw QuoteError("requireNonNull can only be used with sequence literal, not `seq : _*`")
273+
qctx.error("requireNonNull can only be used with sequence literal, not `seq : _*`")
274+
return '{}
275275
}
276276

277277
// generate AST that create array containing the argument name in source (get from calling 'show')

scalactic.dotty/src/main/scala/org/scalactic/Snapshots.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.scalactic
1717

1818
import scala.quoted._
19-
import scala.tasty._
2019

2120
/**
2221
* Case class that stores the name and value of a variable or expression.
@@ -221,8 +220,8 @@ object Snapshots extends Snapshots
221220

222221
object SnapshotsMacro {
223222

224-
def snap(expressions: Expr[Seq[Any]])(implicit refl: Reflection): Expr[SnapshotSeq] = {
225-
import refl._
223+
def snap(expressions: Expr[Seq[Any]])(implicit qctx: QuoteContext): Expr[SnapshotSeq] = {
224+
import qctx.tasty._
226225

227226
def liftSeq(args: Seq[Expr[Snapshot]]): Expr[Seq[Snapshot]] = args match {
228227
case x :: xs => '{ ($x) +: ${ liftSeq(xs) } }
@@ -232,11 +231,12 @@ object SnapshotsMacro {
232231
val snapshots: List[Expr[Snapshot]] = expressions.unseal.underlyingArgument match {
233232
case Typed(Repeated(args, _), _) => // only sequence literal
234233
args.map { arg =>
235-
val str = arg.seal.cast[Any].show(the[Context].withoutColors).toExpr
234+
val str = arg.seal.cast[Any].show.toExpr
236235
'{ Snapshot($str, ${ arg.seal.cast[Any] }) }
237236
}
238237
case arg =>
239-
throw QuoteError("snap can only be used with sequence literal, not `seq : _*`")
238+
qctx.error("snap can only be used with sequence literal, not `seq : _*`")
239+
return '{???}
240240
}
241241

242242
val argumentsS: Expr[Seq[Snapshot]] = liftSeq(snapshots)

scalactic.dotty/src/main/scala/org/scalactic/anyvals/CompileTimeAssertions.scala

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package org.scalactic.anyvals
1818
import org.scalactic.Resources
1919

2020
import scala.quoted._
21-
import scala.tasty._
2221

2322
/**
2423
* Trait providing assertion methods that can be called at compile time from macros
@@ -201,8 +200,8 @@ trait CompileTimeAssertions {
201200
* @param notLiteralMsg a <code>String</code> message to include in the exception thrown if the expression is not a literal
202201
* @param isValid a function used to validate a literal value parsed from the given expression
203202
*/
204-
def ensureValidIntLiteral(value: Expr[Int], notValidMsg: String, notLiteralMsg: String)(isValid: Int => Boolean)(implicit refl: Reflection): Unit = {
205-
import refl._
203+
def ensureValidIntLiteral(value: Expr[Int], notValidMsg: String, notLiteralMsg: String)(isValid: Int => Boolean)(implicit qctx: QuoteContext): Unit = {
204+
import qctx.tasty._
206205

207206
value.unseal.underlyingArgument match {
208207
case Literal(intConst) =>
@@ -236,8 +235,8 @@ trait CompileTimeAssertions {
236235
* @param notLiteralMsg a <code>String</code> message to include in the exception thrown if the expression is not a literal
237236
* @param isValid a function used to validate a literal value parsed from the given expression
238237
*/
239-
def ensureValidLongLiteral(value: Expr[Long], notValidMsg: String, notLiteralMsg: String)(isValid: Long => Boolean)(implicit refl: Reflection): Unit = {
240-
import refl._
238+
def ensureValidLongLiteral(value: Expr[Long], notValidMsg: String, notLiteralMsg: String)(isValid: Long => Boolean)(implicit qctx: QuoteContext): Unit = {
239+
import qctx.tasty._
241240

242241
value.unseal.underlyingArgument match {
243242
case Literal(longConst) =>
@@ -271,8 +270,8 @@ trait CompileTimeAssertions {
271270
* @param notLiteralMsg a <code>String</code> message to include in the exception thrown if the expression is not a literal
272271
* @param isValid a function used to validate a literal value parsed from the given expression
273272
*/
274-
def ensureValidFloatLiteral(value: Expr[Float], notValidMsg: String, notLiteralMsg: String)(isValid: Float => Boolean)(implicit refl: Reflection): Unit = {
275-
import refl._
273+
def ensureValidFloatLiteral(value: Expr[Float], notValidMsg: String, notLiteralMsg: String)(isValid: Float => Boolean)(implicit qctx: QuoteContext): Unit = {
274+
import qctx.tasty._
276275

277276
value.unseal.underlyingArgument match {
278277
case Literal(floatConst) =>
@@ -306,8 +305,8 @@ trait CompileTimeAssertions {
306305
* @param notLiteralMsg a <code>String</code> message to include in the exception thrown if the expression is not a literal
307306
* @param isValid a function used to validate a literal value parsed from the given expression
308307
*/
309-
def ensureValidDoubleLiteral(value: Expr[Double], notValidMsg: String, notLiteralMsg: String)(isValid: Double => Boolean)(implicit refl: Reflection): Unit = {
310-
import refl._
308+
def ensureValidDoubleLiteral(value: Expr[Double], notValidMsg: String, notLiteralMsg: String)(isValid: Double => Boolean)(implicit qctx: QuoteContext): Unit = {
309+
import qctx.tasty._
311310

312311
value.unseal.underlyingArgument match {
313312
case Literal(doubleConst) =>
@@ -341,8 +340,8 @@ trait CompileTimeAssertions {
341340
* @param notLiteralMsg a <code>String</code> message to include in the exception thrown if the expression is not a literal
342341
* @param isValid a function used to validate a literal value parsed from the given expression
343342
*/
344-
def ensureValidStringLiteral(value: Expr[String], notValidMsg: String, notLiteralMsg: String)(isValid: String => Boolean)(implicit refl: Reflection): Unit = {
345-
import refl._
343+
def ensureValidStringLiteral(value: Expr[String], notValidMsg: String, notLiteralMsg: String)(isValid: String => Boolean)(implicit qctx: QuoteContext): Unit = {
344+
import qctx.tasty._
346345

347346
value.unseal.underlyingArgument match {
348347
case Literal(stringConst) =>
@@ -376,8 +375,8 @@ trait CompileTimeAssertions {
376375
* @param notLiteralMsg a <code>String</code> message to include in the exception thrown if the expression is not a literal
377376
* @param isValid a function used to validate a literal value parsed from the given expression
378377
*/
379-
def ensureValidCharLiteral(value: Expr[Char], notValidMsg: String, notLiteralMsg: String)(isValid: Char => Boolean)(implicit refl: Reflection): Unit = {
380-
import refl._
378+
def ensureValidCharLiteral(value: Expr[Char], notValidMsg: String, notLiteralMsg: String)(isValid: Char => Boolean)(implicit qctx: QuoteContext): Unit = {
379+
import qctx.tasty._
381380

382381
value.unseal.underlyingArgument match {
383382
case Literal(charConst) =>

scalactic.dotty/src/main/scala/org/scalactic/anyvals/NumericStringMacro.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ package org.scalactic.anyvals
1717

1818
import org.scalactic.Resources
1919
import scala.quoted._
20-
import scala.tasty._
2120

2221
import CompileTimeAssertions._
2322

2423
object NumericStringMacro {
2524

2625
def isValid(s: String): Boolean = s.forall(c => c >= '0' && c <= '9')
2726

28-
def apply(value: Expr[String])(implicit refl: Reflection): Expr[NumericString] = {
29-
import refl._
27+
def apply(value: Expr[String])(implicit qctx: QuoteContext): Expr[NumericString] = {
28+
import qctx.tasty._
3029

3130
val notValidMsg =
3231
"NumericString.apply can only be invoked on String literals that contain numeric characters, i.e., decimal digits '0' through '9', " +

scalactic.dotty/src/main/scala/org/scalactic/anyvals/PercentageIntMacros.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
package org.scalactic.anyvals
1717

1818
import scala.quoted._
19-
import scala.tasty._
2019

2120
import CompileTimeAssertions._
2221

2322
object PercentageIntMacro {
2423

2524
def isValid(i: Int): Boolean = i >= 0 && i <= 100
2625

27-
def apply(value: Expr[Int])(implicit refl: Reflection): Expr[PercentageInt] = {
28-
import refl._
26+
def apply(value: Expr[Int])(implicit qctx: QuoteContext): Expr[PercentageInt] = {
27+
import qctx.tasty._
2928

3029
val notValidMsg =
3130
"PercentageInt.apply can only be invoked on Int literals between 0 and 100, "+

0 commit comments

Comments
 (0)