groovy

error inside @Category when using multiple properties other than this

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.3
  • Fix Version/s: 1.6.4, 1.7-beta-1
  • Component/s: Compiler
  • Labels:
    None
  • Environment:
    eclipse 3.5M7 + mac os x jdk 1.6 + groovy eclipse 1.6.3.20090514
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

The following sample does not work :

@Category(Tet)
class TestCategory {
	//String getName() {return "hello"}
	String getSuperName() {
		String myname = "" // CENTRAL POINT
		return myname + " yeah"
	}
}

interface Tet {
	String getName()
}

class MyTest implements Tet {
	String getName() {return "hi"}
}

def onetest = new MyTest()

println onetest.getName()

use(TestCategory) {
	println onetest.getSuperName()
}

The stack trace of the error compiling this code with groovy 1.6.3 is :

BUG! exception in phase 'canonicalization' in source unit '/eclipses/workspaces/geny-runtime/groovy.generator.uml2/src/test.groovy' illegal left expression for declaration: org.codehaus.groovy.ast.expr.PropertyExpression@14956342[object: org.codehaus.groovy.ast.expr.VariableExpression@4a1bf766[variable: $this] property: ConstantExpression[myname]]
	at org.codehaus.groovy.ast.expr.DeclarationExpression.check(DeclarationExpression.java:48)
	at org.codehaus.groovy.ast.expr.DeclarationExpression.<init>(DeclarationExpression.java:37)
	at org.codehaus.groovy.ast.expr.DeclarationExpression.transformExpression(DeclarationExpression.java:72)
	at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.transform(ClassCodeExpressionTransformer.java:90)
	at org.codehaus.groovy.transform.CategoryASTTransformation$1.transform(CategoryASTTransformation.java:115)

When using 'name' for assignment at the CENTRAL POINT of the code the error is the same.

When using 'this.name' for assignment at the CENTRAL POINT of the code the error is (a bit more explicit) :

BUG! exception in phase 'canonicalization' in source unit '/eclipses/workspaces/geny-runtime/groovy.generator.uml2/src/test.groovy' illegal left expression for declaration: org.codehaus.groovy.ast.expr.PropertyExpression@292bf0be[object: org.codehaus.groovy.ast.expr.VariableExpression@4a1bf766[variable: $this] property: ConstantExpression[myname]]

Activity

Hide
Louis Foucart added a comment -

ok my mistake about the errors, they are the same !
I put only the stack trace till the CategoryASTTransformation because i think the problem comes from here.

Show
Louis Foucart added a comment - ok my mistake about the errors, they are the same ! I put only the stack trace till the CategoryASTTransformation because i think the problem comes from here.
Hide
Roshan Dawrani added a comment -

Fixed.

Show
Roshan Dawrani added a comment - Fixed.
Hide
Louis Foucart added a comment -

It is ok for property definition but not inside java for loops
Here is the testcase with error on i :

@Category(Tet)
class TestCategory {
//String getName() {return "coucou"}
String getSuperName() { String myname = this.getName() for(int i = 0; i < 5; i++) // CENTRAL POINT myname += i return myname + " yeah" }
}

interface Tet {
String getName()
}

class MyTest implements Tet {
String getName() {return "c'est moi"}
}

def onetest = new MyTest()

println onetest.getName()

use(TestCategory) {
println onetest.getSuperName()
}

Show
Louis Foucart added a comment - It is ok for property definition but not inside java for loops Here is the testcase with error on i : @Category(Tet) class TestCategory { //String getName() {return "coucou"} String getSuperName() { String myname = this.getName() for(int i = 0; i < 5; i++) // CENTRAL POINT myname += i return myname + " yeah" } } interface Tet { String getName() } class MyTest implements Tet { String getName() {return "c'est moi"} } def onetest = new MyTest() println onetest.getName() use(TestCategory) { println onetest.getSuperName() }
Hide
Louis Foucart added a comment -

Using groovy for loops ( 'for(i in 0..5)' ), there is no compilation error but the following runtime error :
Exception in thread "main" groovy.lang.MissingPropertyException: No such property: i for class: MyTest

Show
Louis Foucart added a comment - Using groovy for loops ( 'for(i in 0..5)' ), there is no compilation error but the following runtime error : Exception in thread "main" groovy.lang.MissingPropertyException: No such property: i for class: MyTest
Hide
Roshan Dawrani added a comment -

I see. I will have a look. The fix was tested with the test case provided with originally with the JIRA.

Can you please attach your code in a file? I am not sure about // CENTRAL POINT thing in your code. It is losing all formatting and just to be sure of what all is commented and what all is not, can you please attach the new test case in a text file?

Show
Roshan Dawrani added a comment - I see. I will have a look. The fix was tested with the test case provided with originally with the JIRA. Can you please attach your code in a file? I am not sure about // CENTRAL POINT thing in your code. It is losing all formatting and just to be sure of what all is commented and what all is not, can you please attach the new test case in a text file?
Hide
Roshan Dawrani added a comment -

Hi, I have now fixed the additional failures reported with both forms of for loop. If, any other issue is found that is outside the test cases provided with JIRA, please provide a separate issue for that. Thanks.

Show
Roshan Dawrani added a comment - Hi, I have now fixed the additional failures reported with both forms of for loop. If, any other issue is found that is outside the test cases provided with JIRA, please provide a separate issue for that. Thanks.
Hide
Louis Foucart added a comment -

I just noticed that the text was not well formated. Sorry for that.
Ok about the issues, i thought it was linked because the problem is linked with properties
I filled other issues about @Category and groovy eclipse plugin about the transform.
Thanks for your work !

Show
Louis Foucart added a comment - I just noticed that the text was not well formated. Sorry for that. Ok about the issues, i thought it was linked because the problem is linked with properties I filled other issues about @Category and groovy eclipse plugin about the transform. Thanks for your work !
Hide
Roshan Dawrani added a comment -

You are welcome.

rgds,
Roshan

Show
Roshan Dawrani added a comment - You are welcome. rgds, Roshan

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: