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

@TypeChecked results in Error when groovy casts to BigDecimal ([Static type checking] - Cannot find matching method java.lang.Math#sqrt(java.math.BigDecimal))

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.5.11, 3.0.7, 4.0.0-alpha-2
    • 4.0.5
    • Compiler
    • None

    Description

      From Groovy >2.4 simple calculations cannot be @TypeChecked without loads of casting:

      import groovy.transform.TypeChecked

      @TypeChecked
      def test() {
         Math.sqrt(Math.PI*2)
      }

      => [Static type checking] - Cannot find matching method java.lang.Math#sqrt(java.math.BigDecimal). Please check if the declared type is correct and if the method exists.

      in Groovy 2.4 this was valid code.

      I was able to write a TypeChecker, but it looks pretty ugly and i am not shure, that this does not add other complications.
      Since most of my colleagues are not groovy mains, i prefer forcing the TypeChecker, but this would lead to permanent castings from BigDecimal to double before calling any method.

      Any better workaround or a fix is appreciated.

      Attachments

        1. TypeChecker.groovy
          3 kB
          Andreas Vorgeitz

        Issue Links

          Activity

            People

              Unassigned Unassigned
              vorgi Andreas Vorgeitz
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m