Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11287

Perform constant folding for basic math calculations in CS

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 5.0.0-alpha-4, 4.0.17
    • None
    • None

    Description

      I have the following Groovy code and its Java equivalent:

      @CompileStatic
      final class Main {
          private static final int ONE = 1
      
          static void main(String[] args) {
              int two = ONE + 1
              println two
          }
      }
      
      public final class JavaMain {
          private static final int ONE = 1;
      
          public static void main(String[] args) {
              int two = ONE + 1;
              System.out.println(two);
          }
      }
      

      In Groovy, it currently compiles to:

      int two = ONE + 1

      In Java, the calculation is done at compile-time and inlined:

      int two = 2

      It would be great if Groovy also did this.

      Attachments

        Activity

          People

            Unassigned Unassigned
            paint_ninja Oscar N
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: