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

Support instanceof-like flow typing for class literal switch case

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Would it be possible to extend the maybeFile instanceof File ? maybeFile.canonicalPath : maybeFile.toString() flow typing where maybeFile is seen as File in the true expression position to work for switch?

      This is the kind of construct I am thinking of:

        switch (maybeFile) {
        case File:
          maybeFile.canonicalPath
          break
        default:
          maybeFile.toString()
        }
      

      Currently the example fails in an @TypeChecked or @CompileStatic scope, there is an error for the canonicalPath reference.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: