-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support main methods from traits in Scala 3.4 (200USD Bounty) #89
Comments
This seems reasonable. I thought it would work already, but I've never tried and I guess if you're opening this ticket it doesn't. Should be implementable |
Seems this works in 2.13 but not in 3.4 |
I'll try to get this one working 😸 |
For an example like this one: trait CommandCopy {
@main
def copy(@arg from: String, @arg to: String): Unit = ???
}
class Joined extends CommandCopy {
@main
def test(@arg from: String, @arg to: String): Unit = ???
val parser = ParserForMethods(this)
} The issue manifests itself as a compiler crash:
The code that gets generated looks like this: (new ParserForMethods[Joined](
MethodMains.apply[Joined](
List.apply[MainData[Any, Joined]](
MainData.create[Any, Joined](
"copy",
new main(main.$lessinit$greater$default$1, main.$lessinit$greater$default$2),
List.apply[ArgSig](
ArgSig.create[String, Joined](
"from",
new arg(arg.$lessinit$greater$default$1, arg.$lessinit$greater$default$2, arg.$lessinit$greater$default$3, arg.$lessinit$greater$default$4, arg.$lessinit$greater$default$5, arg.$lessinit$greater$default$6),
None
)(StringRead),
ArgSig.create[String, Joined](
"to",
new arg(arg.$lessinit$greater$default$1, arg.$lessinit$greater$default$2, arg.$lessinit$greater$default$3, arg.$lessinit$greater$default$4, arg.$lessinit$greater$default$5, arg.$lessinit$greater$default$6),
None
)(StringRead)),
((b: Joined, params: [A >: Nothing <: Any] =>> Seq[A][Any]) =>
CommandCopy.this.copy(
Seq.apply[Seq[Any]](params).apply(0).apply(0).asInstanceOf[String],
Seq.apply[Seq[Any]](params).apply(0).apply(1).asInstanceOf[String]
)
)),
MainData.create[Any, Joined](
"test",
new main(main.$lessinit$greater$default$1, main.$lessinit$greater$default$2),
List.apply[ArgSig](
ArgSig.create[String, Joined](
"from",
new arg(arg.$lessinit$greater$default$1, arg.$lessinit$greater$default$2, arg.$lessinit$greater$default$3, arg.$lessinit$greater$default$4, arg.$lessinit$greater$default$5, arg.$lessinit$greater$default$6),
None
)(StringRead),
ArgSig.create[String, Joined](
"to",
new arg(arg.$lessinit$greater$default$1, arg.$lessinit$greater$default$2, arg.$lessinit$greater$default$3, arg.$lessinit$greater$default$4, arg.$lessinit$greater$default$5, arg.$lessinit$greater$default$6),
None
)(StringRead)),
((`b₂`: Joined, `params₂`: [A >: Nothing <: Any] =>> Seq[A][Any]) =>
Joined.this.test(
Seq.apply[Seq[Any]](`params₂`).apply(0).apply(0).asInstanceOf[String],
Seq.apply[Seq[Any]](`params₂`).apply(0).apply(1).asInstanceOf[String]
)
))), (() => Joined.this))
): ParserForMethods[Joined]) The issue itself stems from this: ((b: Joined, params: [A >: Nothing <: Any] =>> Seq[A][Any]) =>
CommandCopy.this.copy(
Seq.apply[Seq[Any]](params).apply(0).apply(0).asInstanceOf[String],
Seq.apply[Seq[Any]](params).apply(0).apply(1).asInstanceOf[String]
)
)), ...so my bet is that this shouldn't be |
From the maintainer Li Haoyi: I'm putting a 200USD bounty on this issue, payable by bank transfer on a merged PR resolving this issue, including a unit test to avoid regression. The issue is straightforward to reproduce.
My Main object has grown too large and I want to split it. I tried to create a trait for each entry point and then making the Main object extends all those traits. But in such case, mainargs does not find any of the @main annotated entry points in any of the traits, while it worked flawlessly when all those methods were together in the same Main object.
Is there any way to support this use case? Without having to duplicate the entry point in all of them, of course.
The text was updated successfully, but these errors were encountered: