-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[backport] SI-10071 SI-8786 varargs methods #5630
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
Conversation
When generating a varargs forwarder for def foo[T](a: T*) the parameter type of the forwarder needs to be Array[Object]. If we generate Array[T] in UnCurry, that would be erased to plain Object, and the method would not be a valid varargs. Unfortunately, setting the parameter type to Array[Object] lead to an invalid generic signature - the generic signature should reflect the real signature. This change adds an attachment to the parameter symbol in the varargs forwarder method and special-cases signature generation. Also cleans up the code to produce the varargs forwarder. For example, type parameter and parameter symbols in the forwarder's method type were not clones, but the same symbols from the original method were re-used. Backported from 0d2760d, with a small tweak (checkVarargs) to make the test work on Java 6, as well as later versions.
Make sure that methods annotated with varargs are properly mixed-in. This commit splits the transformation into an info transformer (that works on all symbols, whether they come from source or binary) and a tree transformer. The gist of this is that the symbol-creation part of the code was moved to the UnCurry info transformer, while tree operations remained in the tree transformer. The newly created symbol is attached to the original method so that the tree transformer can still retrieve the symbol. A few fall outs: - I removed a local map that was identical to TypeParamsVarargsAttachment - moved the said attachment to StdAttachments so it’s visible between reflect.internal and nsc.transform - a couple more comments in UnCurry to honour the boy-scout rule
Cloning the original symbol in its entirety, rather than cloning its type/value parameters individually. `cloneSymbol` takes care of all the tricky substitutions for us!
Hrm, spurious failure we've been seeing more recently: |
note that on the 2.12.x branch we already nixed that test (in #5480) |
(cherry-picking commit a03e7a0) I have repeatedly seen this fail CI runs, including recently as the comment in the test itself says: "I'm not sure this is a great way to test for memory leaks, since we're also testing how good the JVM's GC is, and this is not easily reproduced between machines/over time"
Ah yes, thanks for the reminder! |
/nothingtoseehere -- the earlier failure was in a flaky test that is no longer |
weird, a timeout in scaladoc |
/rebuild |
Weird. Scaladoc hung until the job was aborted again. Could it be because of the info transform changes of 5b972dc? |
/rebuild |
Ok, all seems well. |
Backport of the fix in #5556 as well as relevant earlier work in #5262 (which refactors the relevant code parts in UnCurry, backported as de361df).
This PR rebases and slightly reworks @dragos's original backport in #5557 (to make testing work on java 6 and up).