The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • groovy 'Alpha$TraitAdapter' implements trait 'Alpha' but does not extend self type class 'Thing'

groovy 'Alpha$TraitAdapter' implements trait 'Alpha' but does not extend self type class 'Thing'

Daniel Garcia
December 19, 2021

I'm doing some experiments with traits in scriptrunner and am running the following code in the console

import groovy.transform.SelfType

class Thing {
String color

Thing(String color) {
this.color = color
}

String doSomething() {
"something"
}

@Override
String toString() {
"${color} thing"
}
}

//@SelfType(Thing)
trait Alpha {
String alpha() {
"alpha ${this}"
}

String alphaSomething() {
"alpha ${this.doSomething()}"
}
}

StringBuilder out = new StringBuilder()

out << "<pre class=\"dark\">\n"

Thing blueThing = new Thing("blue")
out << "${blueThing} (${blueThing.class})\n" // blue thing (class Thing)

def alphaThing = blueThing.withTraits Alpha
out << "${alphaThing} (${alphaThing.class})\n" // Thing18_groovyProxy@236366b2 (class Thing18_groovyProxy)
out << "${alphaThing.doSomething()}\n" // something
out << "${alphaThing.alpha()}, ${alphaThing.alphaSomething()}\n" // alpha Thing18_groovyProxy@236366b2, alpha something

out << "</pre>\n"

out.toString()

 

When I remove the comment on @SelfType(Thing) I get the following compilation error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Alpha$TraitAdapterwrapper: -1: class 'Alpha$TraitAdapter' implements trait 'Alpha' but does not extend self type class 'Thing' @ line -1, column -1. 1 error

 

 

 

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.