You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/10/01 06:56:02 UTC
[jira] [Commented] (GROOVY-8336) Static compilation requires
casting inside instanceof check (additional cases)
[ https://issues.apache.org/jira/browse/GROOVY-8336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16187300#comment-16187300 ]
ASF GitHub Bot commented on GROOVY-8336:
----------------------------------------
GitHub user paulk-asert opened a pull request:
https://github.com/apache/groovy/pull/611
GROOVY-8336: Static compilation requires casting inside instanceof ch…
…eck (additional cases)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/paulk-asert/groovy groovy8336
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/611.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #611
----
commit 1b79882184484086220516b182c56a6c78e56ffd
Author: paulk <pa...@asert.com.au>
Date: 2017-10-01T06:53:25Z
GROOVY-8336: Static compilation requires casting inside instanceof check (additional cases)
----
> Static compilation requires casting inside instanceof check (additional cases)
> ------------------------------------------------------------------------------
>
> Key: GROOVY-8336
> URL: https://issues.apache.org/jira/browse/GROOVY-8336
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 2.4.12
> Environment: macOS JDK 1.8
> Reporter: James Kleeh
> Assignee: Paul King
> Fix For: 2.4.13
>
>
> Cloned from GROOVY-8260 to handle these additional cases:
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic
> Date ternaryParam(Object input) {
> input instanceof Date ? input : null
> }
> @CompileStatic
> Date ternaryLocalVar(Object input) {
> Object copy = input
> copy instanceof Date ? copy : null
> }
> @CompileStatic
> Date ifThenElseParam(Object ifThenElseInput) {
> if (ifThenElseInput instanceof Date) {
> ifThenElseInput
> } else {
> null
> }
> }
> @CompileStatic
> Date ifThenElseLocalVar(Object input) {
> Date result
> if (input instanceof Date) {
> result = input
> } else {
> result = null
> }
> result
> }
> class FooBase {}
> class FooChild extends FooBase{}
> @CompileStatic
> FooChild ifThenElseLocalVar2(FooBase input) {
> FooChild result
> if (input instanceof FooChild) {
> result = input
> } else {
> result = null
> }
> result
> }
> def d = new Date()
> assert ternaryParam(42) == null
> assert ternaryParam('foo') == null
> assert ternaryParam(d) == d
> assert ternaryLocalVar(42) == null
> assert ternaryLocalVar('foo') == null
> assert ternaryLocalVar(d) == d
> assert ifThenElseParam(42) == null
> assert ifThenElseParam('foo') == null
> assert ifThenElseParam(d) == d
> assert ifThenElseLocalVar(42) == null
> assert ifThenElseLocalVar('foo') == null
> assert ifThenElseLocalVar(d) == d
> def fc = new FooChild()
> assert ifThenElseLocalVar2(fc) == fc
> assert ifThenElseLocalVar2(new FooBase()) == null
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)