Repository navigation
GROOVY-12620: test a closure or lambda returning an int constant that fits a byte, short or char return type - #3146
Closed
codeconsole wants to merge 3 commits into
Closed
codeconsole wants to merge 3 commits into
codeconsole wants to merge 3 commits into
Conversation
…at fits a byte, short or char return type
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3146 +/- ##
==================================================
+ Coverage 74.3343% 74.3431% +0.0088%
- Complexity 44299 44312 +13
==================================================
Files 1699 1699
Lines 150855 150860 +5
Branches 28754 28755 +1
==================================================
+ Hits 112137 112154 +17
+ Misses 28441 28433 -8
+ Partials 10277 10273 -4 🚀 New features to boost your workflow:
|
…-narrowing # Conflicts: # src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java # src/test/groovy/groovy/transform/stc/CoercionSTCTest.groovy
The check that GROOVY-12616 gave a return to a primitive functional interface type already allows an int constant that fits a byte or short, and char is not range checked (GROOVY-12648), so the branch and helper here can no longer be reached. The tests stay, with the messages that check reports for what does not fit.
🚨 All tests passed but jobs failed 🚨Failed Jobs without Test Failures❌ Build and test / lts (17, windows-latest, 1) 🏷️ Commit: 62d6836 Rerun ControlsClick the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Contributor
Author
|
Closing: master already accepts these. The check GROOVY-12616 gave a value returned to a primitive functional interface type allows an int constant that fits a byte or short, so this PR no longer changes the compiler. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Static type checking used to reject a closure or lambda that returns an int constant for a byte, short or char SAM return type, where Java accepts it (JLS 5.2):
4.0.33, 5.0.8 and 6.0.0 reject it. Master now accepts it: the check GROOVY-12616 gave a value returned to a primitive functional interface type allows a constant that fits. So this PR no longer changes the compiler; it adds the tests.
A constant that does not fit a byte or short, and a non-constant int, are reported as "Possible loss of precision". A char is not range checked, so
C c = { -> -1 }compiles, aschar m() { -1 }does; GROOVY-12648 covers that, so the tests leave it out.Tests
CoercionSTCTest.testCoerceNarrowingConstantReturnToFunctionalInterface, also run byCoercionStaticCompileTests, covers closures and lambdas for byte, short and char, boundary and negative values, block lambdas with several returns, method arguments,ascoercion, static and instance contexts, and the cases that are still rejected. Both classes pass.