Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59d858b

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 863c3c0 commit 59d858b

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-
valexpectedBody= '{ data.generated[t]() }.show
19+
valexpectedBody=
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)

AltStyle によって変換されたページ (->オリジナル) /