[
https://issues.apache.org/jira/browse/GROOVY-12522?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12522:
------------------------------------------
Description:
When a class declares its own version of an extension method of its superclass,
{{super.name()}} and {{super.name}} in dynamic Groovy and under
{{@TypeChecked}} do not find the superclass's extension method:
{code:groovy}
class Numbers extends ArrayList<Integer> {
Numbers() { super([1, 2, 3]) }
Integer first() { -1 }
def test() { super.first() }
}
class Bean {
Map getProperties() { [:] }
def test() { super.properties.containsKey('class') }
}
class Text extends File {
Text(String path) { super(path) }
String getText() { 'own' }
def test() { [super.getText(), super.text] }
}
assert new Numbers().test() == 1 // fails: MissingMethodException: No signature
of method: first for class: java.util.ArrayList
assert new Bean().test() // fails: MissingPropertyException: No such
property: properties for class: Bean
def file = File.createTempFile('text', '.txt')
file.text = 'content'
assert new Text(file.path).test() == ['content', 'content'] // fails:
NullPointerException: charsetName
{code}
{{super.getText()}} calls {{getText(File, String charset)}} with a null
charset, the only {{getText}} left for {{super}}. Without the class's own
method, all three work. Under {{@CompileStatic}} these calls work, but
{{super.text += 'x'}} compiles to a dynamic property access and fails the same
way. Seen in 4.0.33, 5.0.8, 6.0.0 and master.
For {{super}}, a method the class declares is replaced by the MOP method
{{super$2$name}} of the superclass method it overrides, or dropped when there
is none. An extension method has no MOP method, so the class's method is
dropped, and the extension method it replaced in the method index is not
restored.
Expected: {{super.name()}} and {{super.name}} call the superclass's extension
method, as they do when the class does not declare the method.
PR: https://github.com/apache/groovy/pull/3044
was:
When a class declares its own version of an extension method of its superclass,
{{super.name()}} and {{super.name}} in dynamic Groovy and under
{{@TypeChecked}} do not find the superclass's extension method:
{code:groovy}
class Numbers extends ArrayList<Integer> {
Numbers() { super([1, 2, 3]) }
Integer first() { -1 }
def test() { super.first() }
}
class Bean {
Map getProperties() { [:] }
def test() { super.properties.containsKey('class') }
}
class Text extends File {
Text(String path) { super(path) }
String getText() { 'own' }
def test() { [super.getText(), super.text] }
}
assert new Numbers().test() == 1 // fails: MissingMethodException: No signature
of method: first for class: java.util.ArrayList
assert new Bean().test() // fails: MissingPropertyException: No such
property: properties for class: Bean
def file = File.createTempFile('text', '.txt')
file.text = 'content'
assert new Text(file.path).test() == ['content', 'content'] // fails:
NullPointerException: charsetName
{code}
{{super.getText()}} calls {{getText(File, String charset)}} with a null
charset, the only {{getText}} left for {{super}}. Without the class's own
method, all three work. Under {{@CompileStatic}} these calls work, but
{{super.text += 'x'}} compiles to a dynamic property access and fails the same
way. Seen in 4.0.33, 5.0.8, 6.0.0 and master.
For {{super}}, a method the class declares is replaced by the MOP method
{{super$2$name}} of the superclass method it overrides, or dropped when there
is none. An extension method has no MOP method, so the class's method is
dropped, and the extension method it replaced in the method index is not
restored.
Expected: {{super.name()}} and {{super.name}} call the superclass's extension
method, as they do when the class does not declare the method.
> super.name() and super.name miss an extension method that the class overrides
> -----------------------------------------------------------------------------
>
> Key: GROOVY-12522
> URL: https://issues.apache.org/jira/browse/GROOVY-12522
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> When a class declares its own version of an extension method of its
> superclass, {{super.name()}} and {{super.name}} in dynamic Groovy and under
> {{@TypeChecked}} do not find the superclass's extension method:
> {code:groovy}
> class Numbers extends ArrayList<Integer> {
> Numbers() { super([1, 2, 3]) }
> Integer first() { -1 }
> def test() { super.first() }
> }
> class Bean {
> Map getProperties() { [:] }
> def test() { super.properties.containsKey('class') }
> }
> class Text extends File {
> Text(String path) { super(path) }
> String getText() { 'own' }
> def test() { [super.getText(), super.text] }
> }
> assert new Numbers().test() == 1 // fails: MissingMethodException: No
> signature of method: first for class: java.util.ArrayList
> assert new Bean().test() // fails: MissingPropertyException: No such
> property: properties for class: Bean
> def file = File.createTempFile('text', '.txt')
> file.text = 'content'
> assert new Text(file.path).test() == ['content', 'content'] // fails:
> NullPointerException: charsetName
> {code}
> {{super.getText()}} calls {{getText(File, String charset)}} with a null
> charset, the only {{getText}} left for {{super}}. Without the class's own
> method, all three work. Under {{@CompileStatic}} these calls work, but
> {{super.text += 'x'}} compiles to a dynamic property access and fails the
> same way. Seen in 4.0.33, 5.0.8, 6.0.0 and master.
> For {{super}}, a method the class declares is replaced by the MOP method
> {{super$2$name}} of the superclass method it overrides, or dropped when there
> is none. An extension method has no MOP method, so the class's method is
> dropped, and the extension method it replaced in the method index is not
> restored.
> Expected: {{super.name()}} and {{super.name}} call the superclass's extension
> method, as they do when the class does not declare the method.
> PR: https://github.com/apache/groovy/pull/3044
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)