groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7922) Static type checking not strict enough in the presence of ambiguous method matching
Date Sat, 17 Sep 2016 16:04:21 GMT

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

ASF GitHub Bot commented on GROOVY-7922:
----------------------------------------

Github user blackdrag commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/422#discussion_r79286871
  
    --- Diff: src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java ---
    @@ -1157,6 +1141,56 @@ private static ClassNode makeRawType(final ClassNode receiver)
{
             return result;
         }
     
    +    private static void removeMethodInSuperInterface(List<MethodNode> toBeRemoved,
MethodNode one, MethodNode two) {
    +        ClassNode oneDC=one.getDeclaringClass();
    +        ClassNode twoDC=two.getDeclaringClass();
    +        if(oneDC.implementsInterface(twoDC)){
    +            toBeRemoved.add(two);
    +        }else{
    +            toBeRemoved.add(one);
    +        }
    +    }
    +
    +    private static boolean areEquivalentInterfaceMethods(MethodNode one, MethodNode two,
Parameter[] onePars, Parameter[] twoPars) {
    +        return one.getName().equals(two.getName())
    +                && one.getDeclaringClass().isInterface()
    +                && two.getDeclaringClass().isInterface()
    +                && allParameterTypesAreSame(onePars, twoPars);
    +    }
    +
    +    private static void removeSyntheticMethodIfOne(List<MethodNode> toBeRemoved,
MethodNode one, MethodNode two) {
    +        if (one.isSynthetic() && !two.isSynthetic()) {
    +            toBeRemoved.add(one);
    +        } else if (two.isSynthetic() && !one.isSynthetic()) {
    +            toBeRemoved.add(two);
    +        }
    +    }
    +
    +    private static void removeMethodWithSuperReturnType(List<MethodNode> toBeRemoved,
MethodNode one, MethodNode two) {
    +        ClassNode oneRT = one.getReturnType();
    +        ClassNode twoRT = two.getReturnType();
    +        if (oneRT.isDerivedFrom(twoRT) || oneRT.implementsInterface(twoRT)) {
    +            toBeRemoved.add(two);
    +        } else if (twoRT.isDerivedFrom(oneRT) || twoRT.implementsInterface(oneRT)) {
    +            toBeRemoved.add(one);
    +        }
    +    }
    +
    +    private static boolean areOverloadMethodsInSameClass(MethodNode one, MethodNode two){
    +        return one.getName().equals(two.getName()) && one.getDeclaringClass()==two.getDeclaringClass();
    +    }
    +
    +    private static boolean allParameterTypesAreSame(Parameter[] onePars, Parameter[]
twoPars) {
    --- End diff --
    
    I think I can +1 it after the change John suggested


> Static type checking not strict enough in the presence of ambiguous method matching
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-7922
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7922
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Paul King
>
> This example:
> {code}
> import groovy.transform.CompileStatic
> interface FooA {}
> interface FooB {}
> class FooAB implements FooA, FooB {}
> @CompileStatic
> class TestGroovy {
>     static void test() { println new TestGroovy().foo(new FooAB()) }
>     def foo(FooB x) { 43 }
>     def foo(FooA x) { 42 }
> }
> TestGroovy.test()
> {code}
> Should probably throw some kind of ambiguous method error during compilation to match
Java (and dynamic Groovy's runtime error).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message