Skip to content

Commit cbcca0c

Browse files
Fix issue with explicit type for parameters
- Before this fix, trying to remove the [Int] from the option resulted in: cannot infer type; expected type <?> is not fully defined To avoid this, we simply wrap the pre-typed arguments in TypedSplices
1 parent 237e594 commit cbcca0c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

compiler/src/dotty/tools/dotc/ast/MainProxies.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,16 @@ object MainProxies {
184184
/** Turns an annotation (e.g. `@main(40)`) into an instance of the class (e.g. `new scala.main(40)`). */
185185
def instanciateAnnotation(annot: Annotation): Tree =
186186
val argss = {
187-
def recurse(t: Tree, acc: List[List[Tree]]): List[List[Tree]] = t match {
188-
case Apply(t, args: List[Tree]) => recurse(t, extractArgs(args) :: acc)
187+
def recurse(t: tpd.Tree, acc: List[List[Tree]]): List[List[Tree]] = t match {
188+
case Apply(t, args: List[tpd.Tree]) => recurse(t, extractArgs(args) :: acc)
189189
case _ => acc
190190
}
191191

192-
def extractArgs(args: List[Tree]): List[Tree] =
192+
def extractArgs(args: List[tpd.Tree]): List[Tree] =
193193
args.flatMap {
194-
case Typed(SeqLiteral(varargs, _), _) => varargs
195-
case arg @ Select(_, name) => if name.is(DefaultGetterName) then List() else List(arg)
196-
case arg => List(arg)
194+
case Typed(SeqLiteral(varargs, _), _) => varargs.map(arg => TypedSplice(arg))
195+
case arg @ Select(_, name) => if name.is(DefaultGetterName) then List() else List(TypedSplice(arg))
196+
case arg => List(TypedSplice(arg))
197197
}
198198

199199
recurse(annot.tree, Nil)

tests/run/main-annotation-homemade-annot-5.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.annotation.MainAnnotation
22

3-
@mainManyArgs(Some[Int](1)) def foo() = println("Hello world!")
3+
@mainManyArgs(Some(1)) def foo() = println("Hello world!")
44
@mainManyArgs(None) def bar() = println("Hello world!")
55

66
object Test:

0 commit comments

Comments
 (0)