@@ -42,44 +42,50 @@ object MainProxies {
42
42
import untpd ._
43
43
def mainProxy (mainFun : Symbol ) given (ctx : Context ): List [TypeDef ] = {
44
44
val mainAnnotSpan = mainFun.getAnnotation(defn.MainAnnot ).get.tree.span
45
-
45
+ def pos = mainFun.sourcePos
46
46
val argsRef = Ident (nme.args)
47
47
48
- def addArgs (call : untpd.Tree , formals : List [Type ], restpe : Type , idx : Int ): untpd.Tree = {
49
- val args = formals.zipWithIndex map {
50
- (formal, n) =>
51
- val (parserSym, formalElem) =
52
- if (formal.isRepeatedParam) (defn.CLP_parseRemainingArguments , formal.argTypes.head)
53
- else (defn.CLP_parseArgument , formal)
54
- val arg = Apply (
55
- TypeApply (ref(parserSym.termRef), TypeTree (formalElem) :: Nil ),
56
- argsRef :: Literal (Constant (idx + n)) :: Nil )
57
- if (formal.isRepeatedParam) repeated(arg) else arg
48
+ def addArgs (call : untpd.Tree , mt : MethodType , idx : Int ): untpd.Tree = {
49
+ if (mt.isImplicitMethod) {
50
+ ctx.error(s " @main method cannot have implicit parameters " , pos)
51
+ call
58
52
}
59
- val call1 = Apply (call, args)
60
- restpe match {
61
- case restpe : MethodType if ! restpe.isImplicitMethod =>
62
- if (formals.lastOption.getOrElse(NoType ).isRepeatedParam)
63
- ctx.error(s " varargs parameter of @main method must come last " , mainFun.sourcePos)
64
- addArgs(call1, restpe.paramInfos, restpe.resType, idx + args.length)
65
- case _ =>
66
- call1
53
+ else {
54
+ val args = mt.paramInfos.zipWithIndex map {
55
+ (formal, n) =>
56
+ val (parserSym, formalElem) =
57
+ if (formal.isRepeatedParam) (defn.CLP_parseRemainingArguments , formal.argTypes.head)
58
+ else (defn.CLP_parseArgument , formal)
59
+ val arg = Apply (
60
+ TypeApply (ref(parserSym.termRef), TypeTree (formalElem) :: Nil ),
61
+ argsRef :: Literal (Constant (idx + n)) :: Nil )
62
+ if (formal.isRepeatedParam) repeated(arg) else arg
63
+ }
64
+ val call1 = Apply (call, args)
65
+ mt.resType match {
66
+ case restpe : MethodType =>
67
+ if (mt.paramInfos.lastOption.getOrElse(NoType ).isRepeatedParam)
68
+ ctx.error(s " varargs parameter of @main method must come last " , pos)
69
+ addArgs(call1, restpe, idx + args.length)
70
+ case _ =>
71
+ call1
72
+ }
67
73
}
68
74
}
69
75
70
76
var result : List [TypeDef ] = Nil
71
77
if (! mainFun.owner.isStaticOwner)
72
- ctx.error(s " @main method is not statically accessible " , mainFun.sourcePos )
78
+ ctx.error(s " @main method is not statically accessible " , pos )
73
79
else {
74
80
var call = ref(mainFun.termRef)
75
81
mainFun.info match {
76
82
case _ : ExprType =>
77
83
case mt : MethodType =>
78
- if ( ! mt.isImplicitMethod) call = addArgs(call, mt.paramInfos, mt.resultType , 0 )
84
+ call = addArgs(call, mt, 0 )
79
85
case _ : PolyType =>
80
- ctx.error(s " @main method cannot have type parameters " , mainFun.sourcePos )
86
+ ctx.error(s " @main method cannot have type parameters " , pos )
81
87
case _ =>
82
- ctx.error(s " @main can only annotate a method " , mainFun.sourcePos )
88
+ ctx.error(s " @main can only annotate a method " , pos )
83
89
}
84
90
val errVar = Ident (nme.error)
85
91
val handler = CaseDef (
0 commit comments