Skip to content

Commit 01f97bd

Browse files
committed
Revert "Avoid using inline overriding inline"
This reverts commit 3cfd618 We will use overloading instead of overridding: scala/scala3#8601 (review)
1 parent c4b3227 commit 01f97bd

File tree

3 files changed

+99
-16
lines changed

3 files changed

+99
-16
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ trait Assertions extends TripleEquals {
468468
* @throws TestFailedException if the condition is <code>false</code>.
469469
*/
470470
inline def assert(inline condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
471-
${ AssertionsMacro.assert('this, 'condition, 'prettifier, 'pos, '{""}) }
471+
${ AssertionsMacro.assert('{condition}, '{prettifier}, '{pos}, '{""}) }
472472

473473
private[scalatest] def newAssertionFailedException(optionalMessage: Option[String], optionalCause: Option[Throwable], pos: source.Position, analysis: scala.collection.immutable.IndexedSeq[String]): Throwable =
474474
new org.scalatest.exceptions.TestFailedException(toExceptionFunction(optionalMessage), optionalCause, Left(pos), None, analysis)
@@ -527,7 +527,7 @@ trait Assertions extends TripleEquals {
527527
* @throws NullArgumentException if <code>message</code> is <code>null</code>.
528528
*/
529529
inline def assert(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
530-
${ AssertionsMacro.assert('this, 'condition, 'prettifier, 'pos, 'clue) }
530+
${ AssertionsMacro.assert('{condition}, '{prettifier}, '{pos}, '{clue}) }
531531

532532
/**
533533
* Assume that a boolean condition is true.
@@ -575,7 +575,7 @@ trait Assertions extends TripleEquals {
575575
* @throws TestCanceledException if the condition is <code>false</code>.
576576
*/
577577
inline def assume(inline condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
578-
${ AssertionsMacro.assume('this, 'condition, 'prettifier, 'pos, '{""}) }
578+
${ AssertionsMacro.assume('{condition}, '{prettifier}, '{pos}, '{""}) }
579579

580580
/**
581581
* Assume that a boolean condition, described in <code>String</code>
@@ -628,7 +628,7 @@ trait Assertions extends TripleEquals {
628628
* @throws NullArgumentException if <code>message</code> is <code>null</code>.
629629
*/
630630
inline def assume(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
631-
${ AssertionsMacro.assume('this, 'condition, 'prettifier, 'pos, 'clue) }
631+
${ AssertionsMacro.assume('{condition}, '{prettifier}, '{pos}, '{clue}) }
632632

633633
/**
634634
* Asserts that a given string snippet of code does not pass the Scala type checker, failing if the given

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ object AssertionsMacro {
2929
* @param condition original condition expression
3030
* @return transformed expression that performs the assertion check and throw <code>TestFailedException</code> with rich error message if assertion failed
3131
*/
32-
def assert(ths: Expr[Assertions], condition: Expr[Boolean], prettifier: Expr[Prettifier], pos: Expr[source.Position], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Assertion] =
33-
ths match {
34-
case '{ $ths: diagrams.Diagrams } => org.scalatest.DiagrammedAssertionsMacro.assert(condition, prettifier, pos, clue)
35-
case _ => transform('{Assertions.assertionsHelper.macroAssert}, condition, prettifier, pos, clue)
36-
}
32+
def assert(condition: Expr[Boolean], prettifier: Expr[Prettifier], pos: Expr[source.Position], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Assertion] =
33+
transform('{Assertions.assertionsHelper.macroAssert}, condition, prettifier, pos, clue)
3734

3835
/**
3936
* Provides implementation for <code>Assertions.assume(booleanExpr: Boolean)</code>, with rich error message.
@@ -42,12 +39,8 @@ object AssertionsMacro {
4239
* @param condition original condition expression
4340
* @return transformed expression that performs the assumption check and throw <code>TestCanceledException</code> with rich error message if assumption failed
4441
*/
45-
def assume(ths: Expr[Assertions], condition: Expr[Boolean], prettifier: Expr[Prettifier], pos: Expr[source.Position], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Assertion] =
46-
ths match {
47-
case '{ $ths: diagrams.Diagrams } => org.scalatest.DiagrammedAssertionsMacro.assume(condition, prettifier, pos, clue)
48-
case _ => transform('{Assertions.assertionsHelper.macroAssume}, condition, prettifier, pos, clue)
49-
}
50-
42+
def assume(condition: Expr[Boolean], prettifier: Expr[Prettifier], pos: Expr[source.Position], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Assertion] =
43+
transform('{Assertions.assertionsHelper.macroAssume}, condition, prettifier, pos, clue)
5144

5245
def transform(
5346
helper:Expr[(Bool, Any, source.Position) => Assertion],

scalatest.dotty/src/main/scala/org/scalatest/diagrams/Diagrams.scala

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,97 @@ import org.scalatest.compatible.Assertion
154154
*
155155
* <p>Trait <code>DiagrammedAssertions</code> was inspired by Peter Niederwieser's work in <a href="http://code.google.com/p/spock/">Spock</a> and <a href="https://github.com/pniederw/expecty">Expecty</a>.
156156
*/
157-
trait Diagrams extends Assertions
157+
trait Diagrams extends Assertions {
158+
159+
import scala.tasty._
160+
import scala.quoted._
161+
162+
/**
163+
* Assert that a boolean condition is true.
164+
* If the condition is <code>true</code>, this method returns normally.
165+
* Else, it throws <code>TestFailedException</code>.
166+
*
167+
* <p>
168+
* This method is implemented in terms of a Scala macro that will generate a more helpful error message that includes
169+
* a diagram showing expression values.
170+
* </p>
171+
*
172+
* <p>
173+
* If multi-line <code>Boolean</code> is passed in, it will fallback to the macro implementation of <code>Assertions</code>
174+
* that does not contain diagram.
175+
* </p>
176+
*
177+
* @param condition the boolean condition to assert
178+
* @throws TestFailedException if the condition is <code>false</code>.
179+
*/
180+
inline override def assert(inline condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
181+
${ DiagrammedAssertionsMacro.assert('{condition}, '{prettifier}, '{pos}, '{""}) }
182+
183+
/**
184+
* Assert that a boolean condition, described in <code>String</code>
185+
* <code>message</code>, is true.
186+
* If the condition is <code>true</code>, this method returns normally.
187+
* Else, it throws <code>TestFailedException</code> with the
188+
* <code>String</code> obtained by invoking <code>toString</code> on the
189+
* specified <code>clue</code> as the exception's detail message and a
190+
* diagram showing expression values.
191+
*
192+
* <p>
193+
* If multi-line <code>Boolean</code> is passed in, it will fallback to the macro implementation of <code>Assertions</code>
194+
* that does not contain diagram.
195+
* </p>
196+
*
197+
* @param condition the boolean condition to assert
198+
* @param clue An objects whose <code>toString</code> method returns a message to include in a failure report.
199+
* @throws TestFailedException if the condition is <code>false</code>.
200+
* @throws NullArgumentException if <code>message</code> is <code>null</code>.
201+
*/
202+
inline override def assert(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
203+
${ DiagrammedAssertionsMacro.assert('condition, 'prettifier, 'pos, 'clue) }
204+
205+
/**
206+
* Assume that a boolean condition is true.
207+
* If the condition is <code>true</code>, this method returns normally.
208+
* Else, it throws <code>TestCanceledException</code>.
209+
*
210+
* <p>
211+
* This method is implemented in terms of a Scala macro that will generate a more helpful error message that includes
212+
* a diagram showing expression values.
213+
* </p>
214+
*
215+
* <p>
216+
* If multi-line <code>Boolean</code> is passed in, it will fallback to the macro implementation of <code>Assertions</code>
217+
* that does not contain diagram.
218+
* </p>
219+
*
220+
* @param condition the boolean condition to assume
221+
* @throws TestCanceledException if the condition is <code>false</code>.
222+
*/
223+
inline override def assume(inline condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
224+
${ DiagrammedAssertionsMacro.assume('condition, 'prettifier, 'pos, '{""}) }
225+
226+
/**
227+
* Assume that a boolean condition, described in <code>String</code>
228+
* <code>message</code>, is true.
229+
* If the condition is <code>true</code>, this method returns normally.
230+
* Else, it throws <code>TestCanceledException</code> with the
231+
* <code>String</code> obtained by invoking <code>toString</code> on the
232+
* specified <code>clue</code> as the exception's detail message and a
233+
* diagram showing expression values.
234+
*
235+
* <p>
236+
* If multi-line <code>Boolean</code> is passed in, it will fallback to the macro implementation of <code>Assertions</code>
237+
* that does not contain diagram.
238+
* </p>
239+
*
240+
* @param condition the boolean condition to assume
241+
* @param clue An objects whose <code>toString</code> method returns a message to include in a failure report.
242+
* @throws TestCanceledException if the condition is <code>false</code>.
243+
* @throws NullArgumentException if <code>message</code> is <code>null</code>.
244+
*/
245+
inline override def assume(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
246+
${ DiagrammedAssertionsMacro.assume('condition, 'prettifier, 'pos, 'clue) }
247+
}
158248

159249
/**
160250
* Companion object that facilitates the importing of <code>DiagrammedAssertions</code> members as

0 commit comments

Comments
 (0)