You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2024/01/30 22:00:00 UTC
[jira] [Commented] (GROOVY-7984) @SelfType does not allow trait to be added dynamically
[ https://issues.apache.org/jira/browse/GROOVY-7984?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17812491#comment-17812491 ]
Eric Milles commented on GROOVY-7984:
-------------------------------------
{code:groovy}
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'
{code}
> @SelfType does not allow trait to be added dynamically
> ------------------------------------------------------
>
> Key: GROOVY-7984
> URL: https://issues.apache.org/jira/browse/GROOVY-7984
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.4.7
> Environment: windows 7, java 8, groovy script
> Reporter: Denis Jouvin
> Priority: Major
> Labels: trait, traits
>
> When trying to add dynamically a trait T with a SelfType type restriction on class C, to an instance of that class C, the script throws :
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'C@92dae4' with class 'C' to class 'T'
--
This message was sent by Atlassian Jira
(v8.20.10#820010)