You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Keegan Witt (Jira)" <ji...@apache.org> on 2020/10/11 21:05:00 UTC

[jira] [Comment Edited] (GROOVY-9777) Stub missing cast, depending on constructor order

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

Keegan Witt edited comment on GROOVY-9777 at 10/11/20, 9:04 PM:
----------------------------------------------------------------

I think this is because {{selectAccessibleConstructorFromSuper}} chooses the first constructor, but {{printDefaultValue}} (invoked by {{printSpecialConstructorArgs}}) doesn't print the cast for Objects.  You can see this by the fact if you change the first constructor to take a {{GroovyObject}} instead of an {{Object}}, it includes the cast.  That exclusion appears to have been added for GROOVY-2418 (according to commit message).


was (Author: keegan):
I think this is because {{selectAccessibleConstructorFromSuper}} chooses the first constructor, but {{printDefaultValue}} (invoked by {{printSpecialConstructorArgs}}) doesn't print the cast for Objects.  You can see this by the fact if you change the first constructor to take a {{GroovyObject}} instead of an {{Object}}, it includes the cast.  That exclusion was introduced for GROOVY-2418.

> Stub missing cast, depending on constructor order
> -------------------------------------------------
>
>                 Key: GROOVY-9777
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9777
>             Project: Groovy
>          Issue Type: Bug
>          Components: Stub generator / Joint compiler
>    Affects Versions: 3.0.6
>            Reporter: Keegan Witt
>            Priority: Major
>
>  
> {code:java}
> package org.apache.groovy.tests
> class Parent {
>     Parent(Object context) {
>         this(context.class.name)
>     }
>     Parent(Class<?> context) {
>         this(context.name)
>     }
>     Parent(String context) {}
> }
> class Child extends Parent {
>     Child() {
>         super(Child.class.name)
>     }
> }
> {code}
> Generates this stub for Child, missing the cast in the constructor
> {code:java}
> package org.apache.groovy.tests;
> import java.lang.*;
> import java.util.*;
> import java.io.*;
> import java.net.*;
> import groovy.lang.*;
> import groovy.util.*;
> public class Child
>   extends org.apache.groovy.tests.Parent {
> ;
> public Child
> () {
> super (null);
> }
> @groovy.transform.Generated() @groovy.transform.Internal() @java.beans.Transient() public  groovy.lang.MetaClass getMetaClass() { return (groovy.lang.MetaClass)null;}
> @groovy.transform.Generated() @groovy.transform.Internal() public  void setMetaClass(groovy.lang.MetaClass mc) { }
> }
> {code}
> Which causes the Java compilation to fail
> {noformat}
> Child.java:[14,1] reference to Parent is ambiguous
>    both constructor Parent(java.lang.Class<?>) in org.apache.groovy.tests.Parent and constructor Parent(java.lang.String) in org.apache.groovy.tests.Parent match
> {noformat}
>  
> But 
> {code:java}
> package org.apache.groovy.tests
> class Parent {
>     Parent(Class<?> context) {
>         this(context.name)
>     }
>     Parent(String context) {}
>     Parent(Object context) {
>         this(context.class.name)
>     }
> }
> class Child extends Parent {
>     Child() {
>         super(Child.class.name)
>     }
> }
> {code}
> Generates this stub for Child, with the cast in it
> {code:java}
> package org.apache.groovy.tests;
> import java.lang.*;
> import java.util.*;
> import java.io.*;
> import java.net.*;
> import groovy.lang.*;
> import groovy.util.*;
> public class Child
>   extends org.apache.groovy.tests.Parent {
> ;
> public Child
> () {
> super ((java.lang.Class)null);
> }
> @groovy.transform.Generated() @groovy.transform.Internal() @java.beans.Transient() public  groovy.lang.MetaClass getMetaClass() { return (groovy.lang.MetaClass)null;}
> @groovy.transform.Generated() @groovy.transform.Internal() public  void setMetaClass(groovy.lang.MetaClass mc) { }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)