@@ -16,36 +16,34 @@ class data extends MacroAnnotation:
16
16
val clsTpe =
17
17
if typeParams.isEmpty then cls.typeRef
18
18
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]() }
22
22
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)
45
41
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}"
49
47
50
48
51
49
val ctr = cdef.constructor
0 commit comments