Skip to content

Commit

Permalink
GROOVY-7984: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 30, 2024
1 parent 2a6a60b commit f18f92f
Showing 1 changed file with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.codehaus.groovy.transform.traitx

import groovy.test.NotYetImplemented
import groovy.transform.SelfType
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.expr.ClassExpression
Expand Down Expand Up @@ -615,6 +616,35 @@ final class TraitASTTransformationTest {

@Test
void testRuntimeWithTraitsDGM() {
assertScript shell, '''
class C { }
trait T { }
def c = new C()
def t = c.withTraits(T)
def u = t.withTraits(T) // shouldn't fail
'''
}

// GROOVY-7984
@Test @NotYetImplemented
void testRuntimeWithTraitsDGM2() {
assertScript shell, '''
class C {
def m() { 'C' }
}
@SelfType(C)
trait T {
def x() { m() }
}
def c = new C()
def t = c.withTraits(T) // 'T$TraitAdapter' implements trait 'T' but does not extend self type class 'C'
assert t.x() == 'C'
'''
}

@Test
void testRuntimeWithTraitsDGM3() {
assertScript shell, '''
trait Flying {
String fly() {
Expand Down Expand Up @@ -779,17 +809,6 @@ final class TraitASTTransformationTest {
'''
}

@Test
void testProxyGenerationShouldNotFail() {
assertScript shell, '''
trait T { }
class C { }
def o = new C()
def t = o.withTraits(T)
def u = t.withTraits(T) // shouldn't fail
'''
}

@Test
void testShouldNotThrowNPEWithInheritanceUsingExtends() {
assertScript shell, '''
Expand Down

0 comments on commit f18f92f

Please sign in to comment.