groovy
groovy copied to clipboard
GROOVY-7971: @CS flow typing incorrectly casting to map at runtime
Does this change accommodate checking instanceof
under a ternary expression or as part of a larger boolean expression?
int m(o) {
(o instanceof List || o instanceof Map ? o.size() : 1)
}
// or
def x = (o instanceof List || o instanceof Map) && o.isEmpty()
#1269 is not specific to if/else, but as you noted is more restrictive.
Does this change fix the runtime cast exception of your Deque vs. Stack example under static compilation?
@eric-milles No, those cases aren't covered but the if case is. The Stack/Deque case is one of the test cases. The full solution I think will require us to push through Union and Intersection types (though I don't like those names) throughout. I started doing that but never finished. There are lots of hidden assumptions about the current approach throughout the codebase and will take some time. I see this as fixing up a common case while we work longer on the more complete solution. With the if in place, I believe we could have workarounds for the other cases. We could target them as special cases too but it makes the codebase messier the more of these hacks we have.
PR #1269 or PR #1293 ?
The PR seems to break Grails joint build: https://github.com/apache/groovy/runs/836663285?check_suite_focus=true