[Issue 12] @unroll on final or effectively final methods#15
[Issue 12] @unroll on final or effectively final methods#15lihaoyi merged 8 commits intocom-lihaoyi:mainfrom
@unroll on final or effectively final methods#15Conversation
|
@arainko those tests should be converted into negative tests: we should assert the failure and provide an appropriate error message. We should also ensure |
|
So before I go on an adventure: do you have a goto mechanism for testing compilation failures? There's |
|
uTest has |
| def foo(int: Int, @unroll str: String = "1") = int.toString() + str | ||
|
|
||
| def fooInner(int: Int) = { | ||
| def inner(a: Int, @unroll str: String = "1") = str |
There was a problem hiding this comment.
full disclosure - local methods don't seem to get picked up by the plugin at all so they don't go through the validation phase which means that they are just silently ignored (on all Scala versions). I left this test here for visibility and discussion - should I remove the local checks and this definition?
There was a problem hiding this comment.
Is there some way to make them get picked up by the compiler plugin? I would expect compiler plugins to have access to the entire AST of the file to walk through, which should let it find these problematic usages. If not that's fine too, but it seems like it should be doable
There was a problem hiding this comment.
Yeah, I feel like it should be possible - I'll stare at it some more and report back with my findings
There was a problem hiding this comment.
Managed to make it work with an additional traversal of the tree after we've matched a toplevel method.
|
I think this looks fine @arainko, if you could update the PR description with your latest implementation details and (manual?) testing strategy I think we can merge this and close out the bounty |
|
Done, thanks for taking a look! |
|
Thanks @arainko ! please email me your international bank transfer details and I will close out the bounty |
The Scala 3 version of the plugin now closely follows the various checks introduced in the SIP implementation (with the actual impl being a mix of these 3 diffs: diff 1, diff 2, diff 3).
For the Scala 2 version I had to get a tad bit more creative since it lacked (or I just couldn't find the correct combinations of methods, lol) built-in checks for the likes of a method being local (which is now checked by iterating over the owners and checking if any of them is a method) or it had straight up different behavior compared to dotty (e.g. constructors not being considered effectively final).
All of the original test cases (with the exception of
abstractClassMethodandabstractTraitMethodwhich had to be converted intonegativetests) work after annotating their respective classes (or just the methods that were there before) withfinal.There's also the aforementioned
negativemodule which has two variants - a Scala 3 and a Scala 2 one (the only difference between those being an additional check for rejectingtraitconstructors on the Scala 3 side). This module is not automatically checked in any shape or form (pretty much functions as an 'eyeball' test for whoever looks at the code).FTR these are the compilation errors being reported at the time of writing this PR:
Scala 3
Scala 2.13
Scala 2.12
Fixes #12