Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.7
-
None
Description
Assigning a value to a field in a trait doesn't produce a value as a result:
trait A { def foo def bar() { foo = 42 } } class C implements A {} assert new C().bar() == null // should be 42
Groovy treats assignments as expressions, returning the value from the RHS, but traits break that semantics.
Using the AST Browser it can be seen that bar() calls A$Trait$Helper.bar(this), which in turn calls $self.A_foo$set(42) which returns void ($self is an instance of C) - hence null that bar() returns.