@@ -46,31 +46,30 @@ import Annotations.Annotation
46
46
* }
47
47
*/
48
48
object MainProxies {
49
- private type DefaultValues = Map [Int , Tree [_] ]
49
+ private type DefaultValueSymbols = Map [Int , Symbol ]
50
50
private type ParameterAnnotations = Vector [Option [Annotation ]]
51
51
52
52
def mainProxies (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
53
53
import tpd ._
54
54
55
55
/**
56
- * Compute the default values of the function. Since they cannot be infered anymore at this point
57
- * of the compilation, they must be explicitely passed by [[mainProxy ]].
56
+ * Computes the symbols of the default values of the function. Since they cannot be infered anymore at this
57
+ * point of the compilation, they must be explicitely passed by [[mainProxy ]].
58
58
*/
59
- def defaultValues (scope : Tree , funSymbol : Symbol ): DefaultValues =
59
+ def defaultValueSymbols (scope : Tree , funSymbol : Symbol ): DefaultValueSymbols =
60
60
scope match {
61
61
case TypeDef (_, template : Template ) =>
62
62
template.body.flatMap((_ : Tree ) match {
63
63
case dd @ DefDef (name, _, _, _) if name.is(DefaultGetterName ) && name.firstPart == funSymbol.name =>
64
64
val index : Int = name.toString.split(" \\ $" ).last.toInt - 1 // FIXME please!!
65
- val valueTree = dd.rhs
66
- List (index -> valueTree)
65
+ List (index -> dd.symbol)
67
66
case _ => List ()
68
67
}).toMap
69
- case _ => Map [ Int , Tree ]()
68
+ case _ => Map .empty
70
69
}
71
70
72
71
/** Computes the list of main methods present in the code. */
73
- def mainMethods (scope : Tree , stats : List [Tree ]): List [(Symbol , ParameterAnnotations , DefaultValues , Option [Comment ])] = stats.flatMap {
72
+ def mainMethods (scope : Tree , stats : List [Tree ]): List [(Symbol , ParameterAnnotations , DefaultValueSymbols , Option [Comment ])] = stats.flatMap {
74
73
case stat : DefDef =>
75
74
val sym = stat.symbol
76
75
sym.annotations.filter(_.matches(defn.MainAnnot )) match {
@@ -84,7 +83,7 @@ object MainProxies {
84
83
case paramAnnot :: others => report.error(s " parameters cannot have multiple annotations " , paramAnnot.tree); None
85
84
}
86
85
))
87
- (sym, paramAnnotations.toVector, defaultValues (scope, sym), stat.rawComment) :: Nil
86
+ (sym, paramAnnotations.toVector, defaultValueSymbols (scope, sym), stat.rawComment) :: Nil
88
87
case mainAnnot :: others =>
89
88
report.error(s " method cannot have multiple main annotations " , mainAnnot.tree)
90
89
Nil
@@ -100,7 +99,7 @@ object MainProxies {
100
99
}
101
100
102
101
import untpd ._
103
- def mainProxy (mainFun : Symbol , paramAnnotations : ParameterAnnotations , defaultValues : DefaultValues , docComment : Option [Comment ])(using Context ): List [TypeDef ] = {
102
+ def mainProxy (mainFun : Symbol , paramAnnotations : ParameterAnnotations , defaultValueSymbols : DefaultValueSymbols , docComment : Option [Comment ])(using Context ): List [TypeDef ] = {
104
103
val mainAnnot = mainFun.getAnnotation(defn.MainAnnot ).get
105
104
def pos = mainFun.sourcePos
106
105
val mainArgsName : TermName = nme.args
@@ -124,7 +123,6 @@ object MainProxies {
124
123
val argName = mainArgsName ++ n.toString
125
124
126
125
val isRepeated = formal.isRepeatedParam
127
- val defaultValue = defaultValues.get(n)
128
126
129
127
var argRef : Tree = Apply (Ident (argName), Nil )
130
128
var formalType = formal
@@ -157,8 +155,8 @@ object MainProxies {
157
155
* ("documentation", some(lit("my param x")))
158
156
*/
159
157
var assignations : List [(String , Tree )] = Nil
160
- for (dv <- defaultValue )
161
- assignations = (" defaultValue" -> some(dv )) :: assignations
158
+ for (dvSym <- defaultValueSymbols.get(n) )
159
+ assignations = (" defaultValue" -> some(ref(dvSym.termRef) )) :: assignations
162
160
for (annot <- paramAnnotations(n))
163
161
assignations = (" annotation" -> some(instanciateAnnotation(annot))) :: assignations
164
162
for (doc <- documentation.argDocs.get(param))
0 commit comments