[ 
https://issues.apache.org/jira/browse/GROOVY-11012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17718061#comment-17718061
 ] 

Eric Milles commented on GROOVY-11012:
--------------------------------------

This script hits on a different error.  In Groovy, an interface with a default 
method is implemented as a trait.
{code:groovy}
/*interface Bar<T> {
  default T get(x,y) { }
}*/
trait Bar<T> {
  T get(x,y) {
  }
}

class Foo<V> implements Bar<V> {
  static <V> Foo<V> create() { }
}

@TypeChecked test(Foo<Number> foo) {
  Number x = foo.get(null, null) // Cannot assign value of type Object to 
variable of type Number
}

test(Foo.<Number>create())
{code}

> Wrong type is inferred when calling method defined in the parent class
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-11012
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11012
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>
> I have the following program
> {code}
> interface Bar<V> {
>   default V get(Object x, Object y) { return null; }
> }
> class Foo<V> implements Bar<V> {
>   static <V> Foo<V> create() { return null; }
> }
> class Main {
>   static final void test() {
>     Number x = Foo.<Number>create().get(null, null);
>   }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> test.groovy: 11: [Static type checking] - Cannot assign value of type 
> java.lang.Object to variable of type java.lang.Number
>  @ line 11, column 16.
>        Number x = Foo.<Number>create().get(null, null);
>                   ^
> 1 error
> {code}
> h3. Expected behavior
> Compile successfully
> h3. Notes
> Tested against master (commit: 5bcd83e0fde722971f97d479f1a4d6da6cd4aa5f)
> Test cased adapt from the following program that uses the Guava lib
> {code}
> import com.google.common.collect.HashBasedTable;
> class Main {
>   static final void test() {
>     Number x = HashBasedTable.<Number, Number, Number>create().get(null, 
> null);
>   }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to