groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8299) Generate bytecode for interface with default methods
Date Sat, 26 Aug 2017 09:31:01 GMT

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

Daniel Sun commented on GROOVY-8299:
------------------------------------

This is the test code:
{code:java}
            public interface InterfaceA {
                default String hello() {
                    return 'Hello'
                }
            }
            
            class SomeClass implements InterfaceA {}

            assert new SomeClass().hello() == 'Hello'
{code}

We should generate synthetic methods for interface. Luckily,  all of them are static. We can
leverage the power of static method in interface :-)
{code:java}
java.lang.NoSuchMethodError: InterfaceA.$getCallSiteArray()[Lorg/codehaus/groovy/runtime/callsite/CallSite;

	at InterfaceA.hello(TestScript0.groovy)
	at InterfaceA$hello.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at TestScript0.run(TestScript0.groovy:10)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:454)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:492)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:473)
	at groovy.test.GroovyAssert.assertScript(GroovyAssert.java:83)
	at groovy.util.GroovyTestCase.assertScript(GroovyTestCase.java:203)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
	at groovy.bugs.Groovy8299Bug.testInterfaceWithDefaultMethods(Groovy8299Bug.groovy:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:252)
	at junit.framework.TestSuite.run(TestSuite.java:247)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

{code}



> Generate bytecode for interface with default methods
> ----------------------------------------------------
>
>                 Key: GROOVY-8299
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8299
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler
>    Affects Versions: 3.0.0-alpha-1, 2.6.0-alpha-1
>            Reporter: Daniel Sun
>            Assignee: Daniel Sun
>
> Currently the interface with default methods is based on the traits, we should provide
real default methods introduced by Java8.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message