Issue Details (XML | Word | Printable)

Key: GROOVY-2139
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Jochen Theodorou
Reporter: Daniel.Sun
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Can not init instances with super(...)

Created: 25/Sep/07 08:59 AM   Updated: 28/Sep/07 12:06 PM   Resolved: 28/Sep/07 12:06 PM
Component/s: None
Affects Version/s: 1.1-beta-3
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified

Environment: jdk6u2


 Description  « Hide

I failed to compile my old project with groovy1.1beta3, but ok with groovy1.1beta2, so I tried to inspect why.
At last, I found the following code can not be executed properly in groovy1.1beta3, which is abstracted from my project.

Base.groovy
class Base {
	int v

	public Base(int v) {
		this.v = v
	}
}
Derived.groovy
class Derived extends Base {
	int[] vs

	public Derived(vs) {
		super(vs.size)
		this.vs = vs
	}

	public static void main(String[] args) {
		int[] vs = new int[5]
		println vs.length
		Base b = new Derived(vs);
		println b.vs
	}
}


Daniel.Sun added a comment - 25/Sep/07 09:03 AM

error msg:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Derived.groovy: 5: the name vs doesn't refer to a declared variab
le or class. The static scope requires to declare variables before using them. If the variable should have been a class check the spelling.
@ line 5, column 9.
super(vs.size)
^

1 error


Daniel.Sun added a comment - 25/Sep/07 09:08 AM

The Derived class should be

Derived.groovy
class Derived extends Base {
	int[] vs

	public Derived(vs) {
		super(vs.length) // correct  vs.size as vs.length
		this.vs = vs
	}

	public static void main(String[] args) {
		int[] vs = new int[5]
		println vs.length
		Base b = new Derived(vs);
		println b.vs
	}
}

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Derived.groovy: 5: the name vs doesn't refer to a declared variab
le or class. The static scope requires to declare variables before using them. If the variable should have been a class check the spelling.
@ line 5, column 9.
super(vs.length)
^

1 error


Jochen Theodorou added a comment - 28/Sep/07 12:06 PM

fixed