Skip to content
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

compiler should not accept `@varargs` annotation unless it's the last parameter list #11714

Open
SethTisue opened this issue Aug 27, 2019 · 0 comments

Comments

@SethTisue
Copy link
Member

commented Aug 27, 2019

the compiler will accept the @varargs annotation in situations where it shouldn't and gamely generate bad bytecode

for @varargs to work, the variable length argument must be the last argument in the last parameter list. if you have multiple parameter lists, later on downstream you'll get an error like

 class file: /Users/tisue/community.211-11/target-0.9.16/project-builds/twitter-util-715c1151a337e4a30659436b6cafc90bf8f35c6f/util-stats/target/scala-2.11/classes/com/twitter/finagle/stats/StatsReceiver.class
class file contains malformed variable arity method: provideGauge(java.lang.String[],scala.Function0<java.lang.Object>)

for a method such as

@varargs def provideGauge(name: String*)(f: => Float): Unit = { ...

this example comes from twitter/util#255

(...where the problem only cropped up on JDK 11 not JDK 8, so apparently Oracle added some stricter checking on the Java side? but then also it had come up earlier on an earlier JDK at twitter/util#200, so I'm a bit confused about that, but it doesn't matter, the compiler ought to reject it)

this would be a good little getting-started compiler-hacking project for somebody

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.