Skip to content

Commit 09b36c1

Browse files
nicolasstuckismarter
authored andcommitted
Remove need for -Yretain-trees
1 parent 00c82bb commit 09b36c1

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

tests/neg-macros/annot-codegen.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
-- Error: tests/neg-macros/annot-codegen/Test_2.scala:9:4 --------------------------------------------------------------
3-
9 | new Bar("", two, 1, 1.0) // error: body needs to be replaced
2+
-- Error: tests/neg-macros/annot-codegen/Test_2.scala:7:4 --------------------------------------------------------------
3+
7 | new Bar("", two, 1, 1.0) // error: body needs to be replaced
44
| ^^^^^^^^^^^^^^^^^^^^^^^^
55
| Replace the underline code by:
66
| data.generated[Bar]()
7-
-- Error: tests/neg-macros/annot-codegen/Test_2.scala:3:80 -------------------------------------------------------------
8-
3 |@data class Bar(val one: String, val two: Int, val three: Int, val four: Double): // error: additional methods needed
7+
-- Error: tests/neg-macros/annot-codegen/Test_2.scala:1:80 -------------------------------------------------------------
8+
1 |@data class Bar(val one: String, val two: Int, val three: Int, val four: Double): // error: additional methods needed
99
| ^
1010
| @data requires the following additional method(s):
1111
|

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,23 @@ class data extends MacroAnnotation:
1919
val withParam = With(param)
2020
val paramType = cls.declaredField(param).info
2121
val existingOpt =
22-
cls.declaredMethod(withParam).find(o =>
23-
val paramss = o.paramSymss
24-
paramss.size == 1 && paramss(0).size == 1
22+
cdef.body.find(stat =>
23+
val paramss = stat.symbol.paramSymss
24+
stat.symbol.name == withParam
25+
&& paramss.size == 1 && paramss(0).size == 1
2526
&& paramss(0)(0).name == param // FIXME: if the parameter name is incorrect, propose rewriting it
2627
&& paramss(0)(0).info == paramType // FIXME: if the parameter type changed, propose rewriting it
2728
)
2829
existingOpt match
29-
case Some(existing) => existing.tree match
30-
case tree: DefDef =>
31-
tree.rhs match
30+
case Some(tree: DefDef) =>
31+
tree.rhs match
3232
case Some(rhs) => rhs.asExpr match
3333
case '{data.generated[t]()} =>
3434
// The correct method is already present, nothing to do
3535
case _ =>
3636
report.error(s"Replace the underline code by:\n$expectedBody", rhs.pos)
3737
case _ =>
38-
report.error("FIXME: Passing -Yretain-trees is currently needed for this macro to work")
39-
case _ =>
38+
report.error(s"Replace the underline code by:\n${tree.show} = $expectedBody", tree.pos)
4039
case _ =>
4140
// The method is not present
4241
classPatches +=
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// scalac: -Yretain-trees
2-
31
@data class Bar(val one: String, val two: Int, val three: Int, val four: Double): // error: additional methods needed
42
// This definition is OK and will be left as is
53
def withOne(one: String): Bar =
64
data.generated[Bar]()
75

86
def withTwo(two: Int): Bar =
97
new Bar("", two, 1, 1.0) // error: body needs to be replaced
8+
9+
def withThree(three: Int): Bar // error: body needs to be data.generate[Bar]()

0 commit comments

Comments
 (0)