Details
-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.2.0
-
sparc
-
solaris_2.5.1
Description
Name: laC46010 Date: 02/23/99
Constructor invocation can not be the right-hand operand of an assignment
since it doesn't return anything :
(field = field).this(); // legal
field = field.this(); // illegal but javac allows it
(See latest 'Clarifications and Amendments to the Inner Classes Specification' and
JLS 19.8.5 :
ExplicitConstructorInvocation: ...
Primary . this ( ArgumentList opt ) ;
Primary . super ( ArgumentList opt ) ;
this ( ArgumentList opt ) ;
super ( ArgumentList opt ) ;
)
Javac seems to treat unparenthesized assignment here as a Primary, what contradicts the
grammar (JLS 19.12).
Javac (1.2fcs, 1.2.2) compiles the following programs without reporting any errors,
while earlier versions (1.1.x, 1.2beta1,2,3,4) give compilation errors :
1)
------------- test.java -----------
public class test {
static test field = new test();
int var = 0;
class C extends test {
C() {}
C(int a) {
field = field.this(); // compiler should emit an error here
field.var = a;
}
}
public static void main( String args[] ) {
test v1 = new test();
C v2 = v1.new C(10);
System.out.println("v2.var = " + v2.var);
}
}
--------- end of test.java --------
This program outputs :
-----------
> java test
v2.var = 0
-----------
2)
------------- test.java -----------
public class test {
static test field = new test();
int var = 0;
}
class C extends test {
C() {}
C(int a) {
field = field.this(); // compiler should emit an error here
field.var = a;
}
}
--------- end of test.java --------
======================================================================