Implement switch expr type extraction#4968
Conversation
825ecc3 to
b331bd8
Compare
b331bd8 to
c04a989
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4968 +/- ##
===============================================
+ Coverage 58.657% 58.716% +0.059%
- Complexity 2564 2592 +28
===============================================
Files 699 700 +1
Lines 40121 40186 +65
Branches 7314 7323 +9
===============================================
+ Hits 23534 23596 +62
Misses 13620 13620
- Partials 2967 2970 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
This work seems absolutely excellent to me. What do you think @johannescoetzee ? |
|
Looks good to me! Thanks for the contribution @mrjameshamilton I would say the commits are fine if we squash and merge, since everything will be flattened anyways |
|
Thank you for your work. |
I came across an
UnsupportedOperationExceptionlike the following when experimenting with parsing switch expressions:The cause was that the TypeExtractor did not implement the type extraction for switch expressions. For example, I had a case like this which threw the exception because the type of the method call argument (the result of the switch expression) could not be computed:
The PR implements:
- Type extraction for switch expressions based on JLS 15.28.1
If the result expressions all have the same type (which may be the null type), then that is the type of the switch expression.Otherwise, if the type of each result expression is boolean or Boolean, then an unboxing conversion (§5.1.8) is applied to each result expression of type Boolean, and the switch expression has type boolean.
Otherwise, if the type of each result expression is convertible to a numeric type ( §5.1.8), then the type of the switch expression is the result of general numeric promotion (§5.6) applied to the result expressions.
Otherwise, boxing conversion (§5.1.7 ) is applied to each result expression that has a primitive type, after which the type of the switch expression is the result of applying capture conversion (§5.1.10) to the least upper bound (§4.10.4) of the types of the result expressions.
- Validation for switch expressions with no result expressions based on 15.28.1
It is a compile-time error if a switch expression has no result expressions.