Skip to content

Commit b4e0d99

Browse files
committed
Use the same quote for matching and printing using Quotes#matches
We can't just pattern match on it because of #16543.
1 parent 59e33bb commit b4e0d99

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

tests/neg-macros/annot-codegen/Macro_1.scala

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,34 @@ class data extends MacroAnnotation:
1616
val clsTpe =
1717
if typeParams.isEmpty then cls.typeRef
1818
else AppliedType(cls.typeRef, typeParams.map(_.typeRef))
19-
clsTpe.asType match
20-
case '[t] =>
21-
val expectedBody = '{ data.generated[t]() }.show
19+
val expectedBody =
20+
clsTpe.asType match
21+
case '[t] => '{ data.generated[t]() }
2222

23-
val params = paramNames(cls)
24-
for param <- params do
25-
val withParam = With(param)
26-
val paramType = cls.declaredField(param).info
27-
val existingOpt =
28-
cdef.body.find(stat =>
29-
val paramss = stat.symbol.paramSymss
30-
stat.symbol.name == withParam
31-
&& paramss.size == 1 && paramss(0).size == 1
32-
&& paramss(0)(0).name == param // FIXME: if the parameter name is incorrect, propose rewriting it
33-
&& paramss(0)(0).info == paramType // FIXME: if the parameter type changed, propose rewriting it
34-
)
35-
existingOpt match
36-
case Some(tree: DefDef) =>
37-
tree.rhs match
38-
case Some(rhs) => rhs.asExpr match
39-
case '{data.generated[`t`]()} =>
40-
// The correct method is already present, nothing to do
41-
case _ =>
42-
report.error(s"Replace the underline code by:\n$expectedBody", rhs.pos)
43-
case _ =>
44-
report.error(s"Replace the underline code by:\n${tree.show} = $expectedBody", tree.pos)
23+
val params = paramNames(cls)
24+
for param <- params do
25+
val withParam = With(param)
26+
val paramType = cls.declaredField(param).info
27+
val existingOpt =
28+
cdef.body.find(stat =>
29+
val paramss = stat.symbol.paramSymss
30+
stat.symbol.name == withParam
31+
&& paramss.size == 1 && paramss(0).size == 1
32+
&& paramss(0)(0).name == param // FIXME: if the parameter name is incorrect, propose rewriting it
33+
&& paramss(0)(0).info == paramType // FIXME: if the parameter type changed, propose rewriting it
34+
)
35+
existingOpt match
36+
case Some(tree: DefDef) =>
37+
tree.rhs match
38+
case Some(rhs) =>
39+
if !rhs.asExpr.matches(expectedBody) then
40+
report.error(s"Replace the underline code by:\n${expectedBody.show}", rhs.pos)
4541
case _ =>
46-
// The method is not present
47-
classPatches +=
48-
s"def $withParam($param: ${paramType.show}): ${Type.show[t]} = $expectedBody"
42+
report.error(s"Replace the underline code by:\n${tree.show} = ${expectedBody.show}", tree.pos)
43+
case _ =>
44+
// The method is not present
45+
classPatches +=
46+
s"def $withParam($param: ${paramType.show}): ${clsTpe.show} = ${expectedBody.show}"
4947

5048

5149
val ctr = cdef.constructor

0 commit comments

Comments
 (0)