You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Christopher Smith (JIRA)" <ji...@apache.org> on 2015/06/07 16:04:00 UTC
[jira] [Commented] (GROOVY-7449) power operator needs specific
typing for result
[ https://issues.apache.org/jira/browse/GROOVY-7449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14576245#comment-14576245 ]
Christopher Smith commented on GROOVY-7449:
-------------------------------------------
I understand the issues with this on a general scale, but in my case, I'm particularly looking at a compile-time constant. Would it be feasible to implement a rule such as https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.2 that could identify at compile time that {{10 **4}} would fit into an {{int}} and type it accordingly?
> power operator needs specific typing for result
> -----------------------------------------------
>
> Key: GROOVY-7449
> URL: https://issues.apache.org/jira/browse/GROOVY-7449
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.4.3
> Reporter: Christopher Smith
> Assignee: Cédric Champeau
> Priority: Minor
>
> I wanted to use the power operator to set a static constant field:
> {code}
> public static final int DIGITS_IN_CODE = 4
> static final int mod = 10 ** DIGITS_IN_CODE
> {code}
> This results in a compile-time exception when used with {{@CompileStatic}}:
> {code}
> Groovy:[Static type checking] - Cannot assign value of type java.lang.Number to variable of type int
> {code}
> Replacing the symbolic constant with just {{10 ** 4}} produces the same bug. It appears that power expressions are not getting resolved until runtime even if they're compile-time constant expressions.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)