@@ -24,16 +24,6 @@ object desugar {
24
24
25
25
// ----- TypeTrees that refer to other tree's symbols -------------------
26
26
27
- /** A marker tree used as the original for TypeTrees that get their type by taking
28
- * the typeRef of some other tree's symbol. (currently unused)
29
- */
30
- val TypeRefOfSym = new TypeTree (EmptyTree )
31
-
32
- /** A marker tree used as the original for TypeTrees that get their type by taking
33
- * the result type of the info of some other tree's symbol.
34
- */
35
- val InfoOfSym = new TypeTree (EmptyTree )
36
-
37
27
/** Attachment key containing TypeTrees whose type is computed
38
28
* from the symbol in this type. These type trees have marker trees
39
29
* TypeRefOfSym or InfoOfSym as their originals.
@@ -46,15 +36,19 @@ object desugar {
46
36
*/
47
37
val OriginalSymbol = new Attachment .Key [Symbol ]
48
38
49
- /** A type tree that is marked to get its type by taking
50
- * the typeRef of some other tree's symbol. Enters the type tree
51
- * in the References attachment of the `original` tree as a side effect.
39
+ /** A type tree that gets its type from some other tree's symbol. Enters the
40
+ * type tree in the References attachment of the `from` tree as a side effect.
52
41
*/
53
- def refTypeTree (original : Tree , marker : TypeTree ): TypeTree = {
54
- val result = TypeTree (marker)
55
- val existing = original.attachmentOrElse(References , Nil )
56
- original.putAttachment(References , result :: existing)
57
- result
42
+ abstract class DerivedTypeTree (from : Tree ) extends TypeTree (EmptyTree ) {
43
+ val existing = from.attachmentOrElse(References , Nil )
44
+ from.putAttachment(References , this :: existing)
45
+
46
+ /** The method that computes the type of this tree */
47
+ def derivedType (originalSym : Symbol )(implicit ctx : Context ): Type
48
+ }
49
+
50
+ class SetterParam (vdef : ValDef ) extends DerivedTypeTree (vdef) {
51
+ def derivedType (vsym : Symbol )(implicit ctx : Context ) = vsym.info.resultType
58
52
}
59
53
60
54
// ----- Desugar methods -------------------------------------------------
@@ -73,7 +67,7 @@ object desugar {
73
67
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos ?
74
68
// right now vdef maps via expandedTree to a thicket which concerns itself.
75
69
// I don't see a problem with that but if there is one we can avoid it by making a copy here.
76
- val setterParam = makeSyntheticParameter(tpt = refTypeTree (vdef, InfoOfSym ))
70
+ val setterParam = makeSyntheticParameter(tpt = new SetterParam (vdef))
77
71
val setterRhs = if (vdef.rhs.isEmpty) EmptyTree else unitLiteral
78
72
val setter = cpy.DefDef (vdef,
79
73
mods | Accessor , name.setterName, Nil , (setterParam :: Nil ) :: Nil ,
0 commit comments