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

STC: Support flow typing for (a.class == C && a...) and similar expressions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      Is it possible to extend the x instanceof C && x.methodOfC() flow typing to include:

      • x.class == C && x...
      • x.getClass() == C && x...
      • x.getClass() === C && x...
      • x.getClass().is(C) && x...
      • and maybe even isCase and in?

      Example:

      @TypeChecked
      def m(def obj) {
      //def a = (obj instanceof String    && obj.equalsIgnoreCase('a'))
        def b = (obj.getClass() == String && obj.equalsIgnoreCase('b'))
        def c = (obj.class == String      && obj.equalsIgnoreCase('c'))
        def d = (obj.class.is(String)     && obj.equalsIgnoreCase('d'))
        def e = (obj.class.isCase(String) && obj.equalsIgnoreCase('e'))
        def f = (obj in [String, StringBuffer] && obj.somethingFromLUB()) // bonus
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: