Skip to content

Commit 0496200

Browse files
authored
Merge pull request #6074 from dotty-staging/fix-6048
Fix #6048: set missing position in value class rewiring
2 parents 4823308 + a7ed132 commit 0496200

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

compiler/src/dotty/tools/dotc/transform/VCInlineMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class VCInlineMethods extends MiniPhase with IdentityDenotTransformer {
9292
tree // The rewiring will be handled by a fully-applied parent node
9393
case _ =>
9494
if (isMethodWithExtension(tree.symbol))
95-
rewire(tree).ensureConforms(tree.tpe)
95+
rewire(tree).ensureConforms(tree.tpe).withSpan(tree.span)
9696
else
9797
tree
9898
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object scalatest {
5+
6+
inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) }
7+
8+
def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
9+
import refl._
10+
import util._
11+
import quoted.Toolbox.Default._
12+
13+
def isImplicitMethodType(tp: Type): Boolean =
14+
Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
15+
16+
cond.unseal.underlyingArgument match {
17+
case t @ Term.Apply(Term.Select(lhs, op), rhs :: Nil) =>
18+
let(lhs) { left =>
19+
let(rhs) { right =>
20+
val app = Term.Select.overloaded(left, op, Nil, right :: Nil)
21+
let(app) { result =>
22+
val l = left.seal[Any]
23+
val r = right.seal[Any]
24+
val b = result.seal[Boolean]
25+
val code = '{ scala.Predef.assert($b) }
26+
code.unseal
27+
}
28+
}
29+
}.seal[Unit]
30+
case Term.Apply(f @ Term.Apply(Term.Select(Term.Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
31+
if isImplicitMethodType(f.tpe) =>
32+
let(lhs) { left =>
33+
let(rhs) { right =>
34+
val app = Term.Select.overloaded(Term.Apply(qual, left :: Nil), op, Nil, right :: Nil)
35+
let(Term.Apply(app, implicits)) { result =>
36+
val l = left.seal[Any]
37+
val r = right.seal[Any]
38+
val b = result.seal[Boolean]
39+
val code = '{ scala.Predef.assert($b) }
40+
code.unseal
41+
}
42+
}
43+
}.seal[Unit]
44+
}
45+
}
46+
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
import scalatest._
3+
4+
implicit class AnyOps(x: String) extends AnyVal {
5+
def *(y: String): String = x + ", " + y
6+
}
7+
8+
def main(args: Array[String]): Unit = {
9+
assert(("hello" * "world") == "hello, world")
10+
}
11+
}

0 commit comments

Comments
 (0)