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

Static type checking error when assigning BigInteger child to BigInteger var from static context

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.9, 2.2.0-rc-3
    • 2.2.1
    • Static Type Checker
    • None

    Description

      A static type checking error "[Static type checking] - Cannot assign value of type MyInteger to variable of type java.math.BigInteger" when assigning child class of BigInteger to a BigInteger variable. Occurs only from static context when @CompileStatic enabled. Does not occur for similar case for BigDecimal.

      Example:

      public class MyDecimal extends java.math.BigDecimal {
        public MyDecimal(String s) {super(s);}
      }
      
      public class MyInteger extends java.math.BigInteger {
        public MyInteger(String s) {super(s);}
      }
      
      public class Foo {
      
        @groovy.transform.CompileStatic
        public static void run() {
          BigDecimal d = new MyDecimal("3.0");
          BigInteger i = new MyInteger("3"); //compile error: [Static type checking]
        }
      }
      
      Foo.run();
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            mahool Mike Hoolehan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: