Skip to content

Commit 00dc124

Browse files
liufengyuncheeseng
authored andcommitted
Fix compiler options: allow global scalac options, and got it to build again.
1 parent 256b82e commit 00dc124

File tree

11 files changed

+203
-382
lines changed

11 files changed

+203
-382
lines changed

project/DottyBuild.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ trait DottyBuild { this: BuildCommons =>
1313

1414
// List of available night build at https://repo1.maven.org/maven2/ch/epfl/lamp/dotty-compiler_0.14/
1515
// lazy val dottyVersion = dottyLatestNightlyBuild.get
16-
lazy val dottyVersion = "0.19.0"
16+
lazy val dottyVersion = "0.21.0-RC1"
1717
lazy val dottySettings = List(
1818
scalaVersion := dottyVersion,
1919
libraryDependencies := libraryDependencies.value.map(_.withDottyCompat(scalaVersion.value)),
20-
scalacOptions := List("-language:implicitConversions", "-noindent", "-Xprint-suspension")
20+
scalacOptions ++= List("-language:implicitConversions", "-noindent", "-Xprint-suspension")
2121
)
2222

2323
lazy val scalacticDotty = Project("scalacticDotty", file("scalactic.dotty"))

project/scalatest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ object ScalatestBuild extends BuildCommons with DottyBuild with NativeBuild with
140140

141141
def sharedSettings: Seq[Setting[_]] =
142142
commonSharedSettings ++ Seq(
143-
scalaVersion := "2.13.0",
143+
scalaVersion := "2.13.1",
144144
crossScalaVersions := supportedScalaVersions,
145145
libraryDependencies ++= {
146146
if (isDotty.value)

scalatest.dotty/src/main/scala/org/scalatest/CompileMacro.scala

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

1818
import org.scalactic._
19+
import org.scalatest.words.{TypeCheckWord, CompileWord}
1920
import org.scalatest.exceptions._
2021

2122
import scala.quoted._
@@ -157,4 +158,161 @@ object CompileMacro {
157158
)($prettifier)
158159
}
159160
}
161+
162+
// check that a code snippet does not compile
163+
def assertNotCompileImpl[T](self: Expr[T], compileWord: Expr[CompileWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit qctx: QuoteContext): Expr[Assertion] = {
164+
import qctx.tasty.{_, given}
165+
166+
// parse and type check a code snippet, generate code to throw TestFailedException if both parse and type check succeeded
167+
def checkNotCompile(code: String): Expr[Assertion] =
168+
if (/*!typeChecks(code)*/ true) '{ Succeeded } // FIXME
169+
else '{
170+
val messageExpr = Resources.expectedCompileErrorButGotNone(${ Expr(code) })
171+
throw new TestFailedException((_: StackDepthException) => Some(messageExpr), None, $pos)
172+
}
173+
174+
self.unseal.underlyingArgument match {
175+
176+
case Apply(
177+
Apply(
178+
Select(_, shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
179+
List(
180+
Literal(Constant(code: String))
181+
)
182+
),
183+
_
184+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
185+
// LHS is a normal string literal, call checkCompile with the extracted code string to generate code
186+
checkNotCompile(code)
187+
188+
case Apply(
189+
Apply(
190+
Ident(shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
191+
List(
192+
Literal(Constant(code: String))
193+
)
194+
),
195+
_
196+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
197+
checkNotCompile(code)
198+
199+
case other =>
200+
qctx.error("The '" + shouldOrMust + " compile' syntax only works with String literals.")
201+
'{???}
202+
}
203+
}
204+
205+
// used by shouldNot compile syntax, delegate to assertNotCompileImpl to generate code
206+
def shouldNotCompileImpl(self: Expr[Matchers#AnyShouldWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
207+
assertNotCompileImpl(self, compileWord, pos)("should")
208+
209+
// used by mustNot compile syntax, delegate to assertNotCompileImpl to generate code
210+
def mustNotCompileImpl(self: Expr[MustMatchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
211+
assertNotCompileImpl(self, compileWord, pos)("must")
212+
213+
// check that a code snippet does not compile
214+
def assertNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit qctx: QuoteContext): Expr[Assertion] = {
215+
import qctx.tasty.{_, given}
216+
217+
// parse and type check a code snippet, generate code to throw TestFailedException if both parse and type check succeeded
218+
def checkNotTypeCheck(code: String): Expr[Assertion] =
219+
if (/*!typeChecks(code)*/ true) '{ Succeeded } // FIXME
220+
else '{
221+
val messageExpr = Resources.expectedTypeErrorButGotNone(${ Expr(code) })
222+
throw new TestFailedException((_: StackDepthException) => Some(messageExpr), None, $pos)
223+
}
224+
225+
val methodName = shouldOrMust + "Not"
226+
227+
self.unseal.underlyingArgument match {
228+
case Apply(
229+
Apply(
230+
Select(_, shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
231+
List(
232+
Literal(code)
233+
)
234+
),
235+
_
236+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
237+
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
238+
checkNotTypeCheck(code.toString)
239+
240+
case Apply(
241+
Apply(
242+
Ident(shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
243+
List(
244+
Literal(Constant(code: String))
245+
)
246+
),
247+
_
248+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
249+
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
250+
checkNotTypeCheck(code.toString)
251+
252+
case _ =>
253+
qctx.error("The '" + shouldOrMust + "Not typeCheck' syntax only works with String literals.")
254+
'{???}
255+
}
256+
}
257+
258+
// used by shouldNot typeCheck syntax, delegate to assertNotTypeCheckImpl to generate code
259+
def shouldNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
260+
assertNotTypeCheckImpl(self, typeCheckWord, pos)("should")
261+
262+
// used by mustNot typeCheck syntax, delegate to assertNotTypeCheckImpl to generate code
263+
def mustNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
264+
assertNotTypeCheckImpl(self, typeCheckWord, pos)("must")
265+
266+
// check that a code snippet compiles
267+
def assertCompileImpl[T](self: Expr[T], compileWord: Expr[CompileWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit qctx: QuoteContext): Expr[Assertion] = {
268+
import qctx.tasty.{_, given}
269+
270+
// parse and type check a code snippet, generate code to throw TestFailedException if both parse and type check succeeded
271+
def checkCompile(code: String): Expr[Assertion] =
272+
if (/*typeChecks(code)*/ true) '{ Succeeded } // FIXME
273+
else '{
274+
val messageExpr = Resources.expectedNoErrorButGotTypeError("", ${ Expr(code) })
275+
throw new TestFailedException((_: StackDepthException) => Some(messageExpr), None, $pos)
276+
}
277+
278+
self.unseal.underlyingArgument match {
279+
280+
case Apply(
281+
Apply(
282+
Select(_, shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
283+
List(
284+
Literal(Constant(code: String))
285+
)
286+
),
287+
_
288+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
289+
// LHS is a normal string literal, call checkCompile with the extracted code string to generate code
290+
checkCompile(code.toString)
291+
292+
case Apply(
293+
Apply(
294+
Ident(shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
295+
List(
296+
Literal(Constant(code: String))
297+
)
298+
),
299+
_
300+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
301+
// LHS is a normal string literal, call checkCompile with the extracted code string to generate code
302+
checkCompile(code.toString)
303+
304+
case other =>
305+
println("###other: " + other)
306+
qctx.error("The '" + shouldOrMust + " compile' syntax only works with String literals.")
307+
'{???}
308+
}
309+
}
310+
311+
// used by should compile syntax, delegate to assertCompileImpl to generate code
312+
def shouldCompileImpl(self: Expr[Matchers#AnyShouldWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
313+
assertCompileImpl(self, compileWord, pos)("should")
314+
315+
// used by should compile syntax, delegate to assertCompileImpl to generate code
316+
def mustCompileImpl(self: Expr[MustMatchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
317+
assertCompileImpl(self, compileWord, pos)("must")
160318
}

scalatest.dotty/src/main/scala/org/scalatest/matchers/Matcher.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.scalatest.matchers
1717

1818
import org.scalactic._
1919
import org.scalatest.enablers._
20+
import org.scalatest.words._
2021
import org.scalatest.matchers.dsl._
2122
import org.scalatest.FailureMessages
2223
import org.scalatest.matchers.MatchersHelper.andMatchersAndApply

scalatest.dotty/src/main/scala/org/scalatest/matchers/MatchersCompileMacro.scala

Lines changed: 0 additions & 114 deletions
This file was deleted.

scalatest.dotty/src/main/scala/org/scalatest/matchers/TypeMatcherMacro.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,42 @@ object TypeMatcherMacro {
168168
'{ ($self).owner.or($rhs) }
169169
}
170170

171+
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAType, used by 'shouldBe a [type]' syntax
172+
def shouldBeATypeImpl(self: Expr[org.scalatest.matchers.should.Matchers#AnyShouldWrapper[_]], aType: Expr[ResultOfATypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
173+
import qctx.tasty.{_, given}
174+
checkTypeParameter(qctx)(aType.unseal, "a")
175+
'{
176+
TypeMatcherHelper.assertAType(($self).leftSideValue, $aType, ($self).prettifier, ($self).pos)
177+
}
178+
}
179+
180+
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAType, used by 'mustBe a [type]' syntax
181+
def mustBeATypeImpl(self: Expr[org.scalatest.matchers.must.Matchers#AnyMustWrapper[_]], aType: Expr[ResultOfATypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
182+
import qctx.tasty.{_, given}
183+
checkTypeParameter(qctx)(aType.unseal, "a")
184+
'{
185+
TypeMatcherHelper.assertAType(($self).leftSideValue, $aType, ($self).prettifier, ($self).pos)
186+
}
187+
}
188+
189+
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAType, used by 'shouldBe an [type]' syntax
190+
def shouldBeAnTypeImpl(self: Expr[org.scalatest.matchers.should.Matchers#AnyShouldWrapper[_]], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
191+
import qctx.tasty.{_, given}
192+
checkTypeParameter(qctx)(anType.unseal, "an")
193+
'{
194+
TypeMatcherHelper.assertAnType(($self).leftSideValue, $anType, ($self).prettifier, ($self).pos)
195+
}
196+
}
197+
198+
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAnType, used by 'mustBe an [type]' syntax
199+
def mustBeAnTypeImpl(self: Expr[org.scalatest.matchers.must.Matchers#AnyMustWrapper[_]], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
200+
import qctx.tasty.{_, given}
201+
checkTypeParameter(qctx)(anType.unseal, "an")
202+
'{
203+
TypeMatcherHelper.assertAnType(($self).leftSideValue, $anType, ($self).prettifier, ($self).pos)
204+
}
205+
}
206+
171207
// /*def expectTypeImpl(context: Context)(tree: context.Tree, beMethodName: String, assertMethodName: String): context.Expr[org.scalatest.Fact] = {
172208
// import context.universe._
173209

0 commit comments

Comments
 (0)