Kenzie Togami created GROOVY-8833: ------------------------------------- Summary: @Canonical creates invalid hashCode Key: GROOVY-8833 URL: https://issues.apache.org/jira/browse/GROOVY-8833 Project: Groovy Issue Type: Bug Components: Compiler Affects Versions: 2.5.3 Reporter: Kenzie Togami
Applying {{@Canonical}} to a class will generate an invalid hashCode method that throws a runtime cast exception. This does not happen if you apply the individual annotations by themselves. These tests can be injected into a Groovy test class to see the problem: [https://gist.github.com/kenzierocks/fb0932756c3955a7ddbc0b710791af11] I suspect the underlying cause is that {{@EqualsAndHashCode}} does not set {{accessedVariable}} on its {{_result}} variable, which causes the verifier to overwrite it with {{toString}}'s {{_result}} variable (see {{FinalVariableAnalyzer#fixVar}}). This results in an invalid cast. I observed this behavior while debugging the compiler. I'm not sure why this doesn't also happen if the two annotations are applied by themselves, rather than via {{@Canonical}}. I was able to fix this problem by setting {{_result}} to reference itself in the AST, but perhaps that's not the right fix here. -- This message was sent by Atlassian JIRA (v7.6.3#76005)