groovy

Can not init instances with super(...)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.1-beta-3
  • Fix Version/s: 1.1-rc-1
  • Component/s: None
  • Labels:
    None
  • Environment:
    jdk6u2
  • Number of attachments :
    0

Description

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
	}
}

Activity

Hide
Daniel.Sun added a comment -

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

Show
Daniel.Sun added a comment - 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
Hide
Daniel.Sun added a comment -

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

Show
Daniel.Sun added a comment - 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
Hide
blackdrag blackdrag added a comment -

fixed

Show
blackdrag blackdrag added a comment - fixed

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: