[
https://issues.apache.org/jira/browse/GROOVY-11888?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-11888:
---------------------------------
Description:
The following {{instanceof}} checks worked under Groovy 5 and are failing under
Groovy 6 (alpha):
{code:groovy}
@CompileStatic test24(Object x) {
if (x instanceof String || x instanceof List) {
assert x.toString() != null
}
}
test24('hello')
test24([1, 2])
@CompileStatic test25(Object x) {
if (!(x instanceof String || x instanceof Integer)) {
assert x != null
} else {
assert x instanceof String || x instanceof Integer
}
}
test25('hello')
test25(42)
test25(3.14)
{code}
This case works under Groovy 4, fails under Groovy 5 (see GROOVY-11754) but is
expected to work for Groovy 6 (alpha):
{code:groovy}
@CompileStatic test26(Number n) {
if (n instanceof Integer || n.intValue() > 0) {
assert n.intValue() >= 0 // Cannot find matching method (java.lang.Integer
| java.lang.Number)#intValue()
}
}
test26(42)
test26(1.5)
{code}
> STC: method resolution fails for UnionTypeClassNode due to premature
> covariant elimination
> ------------------------------------------------------------------------------------------
>
> Key: GROOVY-11888
> URL: https://issues.apache.org/jira/browse/GROOVY-11888
> Project: Groovy
> Issue Type: Bug
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> The following {{instanceof}} checks worked under Groovy 5 and are failing
> under Groovy 6 (alpha):
> {code:groovy}
> @CompileStatic test24(Object x) {
> if (x instanceof String || x instanceof List) {
> assert x.toString() != null
> }
> }
> test24('hello')
> test24([1, 2])
> @CompileStatic test25(Object x) {
> if (!(x instanceof String || x instanceof Integer)) {
> assert x != null
> } else {
> assert x instanceof String || x instanceof Integer
> }
> }
> test25('hello')
> test25(42)
> test25(3.14)
> {code}
> This case works under Groovy 4, fails under Groovy 5 (see GROOVY-11754) but
> is expected to work for Groovy 6 (alpha):
> {code:groovy}
> @CompileStatic test26(Number n) {
> if (n instanceof Integer || n.intValue() > 0) {
> assert n.intValue() >= 0 // Cannot find matching method
> (java.lang.Integer | java.lang.Number)#intValue()
> }
> }
> test26(42)
> test26(1.5)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)