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

STC: non ambiguous constructor reference when subclass is used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2
    • None
    • None

    Description

      import groovy.transform.*
      
      class Expr {}
      class VarExpr extends Expr {}
      
      class TupList {
          TupList(Expr e1) {}
          TupList(Expr[] es) {}
      }
      
      class ArgList extends TupList {
          ArgList(Expr e1) { super(e1) }
          ArgList(Expr[] es) { super(es) }
      }
      
      @TypeChecked
      class Bug4 {
          void test() {
              new ArgList(new VarExpr())
          }
      }
      
      new Bug4().test()
      

      Yields:

      [Static type checking] - Reference to method is ambiguous. Cannot choose between [MethodNode@745724997[void <init>(Expr)], MethodNode@685460687[void <init>(Expr[])]]
       at line: 19, column: 9
      

      It's happening somehow because VarExpr is a child of Expr.
      In the case of just creating and passing an Expr, things are fine.

      Attachments

        Activity

          People

            melix Cédric Champeau
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: