[kaffe] Re: error:Switch label must be constant [JLS 14.10]
Ito Kazumitsu
ito.kazumitsu@hitachi-cable.co.jp
Wed Nov 19 02:29:02 2003
Hi,
In message "Re: error:Switch label must be constant [JLS 14.10]"
on 03/10/29, Ito Kazumitsu <ito.kazumitsu@hitachi-cable.co.jp> writes:
> bash$ java at.dms.kjc.Main Trigger.java TriggerDef.java
> TriggerDef.java:10: error:Switch label must be constant [JLS 14.10]
> TriggerDef.java:4: error:Method "indexToRight" must return a value [JLS 8.4.5]
For the purpose of debugging, I patched JFieldAccessExpression.java:
--- kopi-2.1B/src/kjc/JFieldAccessExpression.java 2002-07-16 03:53:34.000000000 +0900
+++ JFieldAccessExpression.java 2003-10-29 10:21:02.000000000 +0900
@@ -120,6 +120,12 @@
// - Qualified names of the form TypeName . Identifier that refer to
// final variables whose initializers are constant expressions
+ System.err.println("## " + ident + " isConstant(): constantPrefix = " + constantPrefix +
+ " field.isFinal()=" + field.isFinal() +
+ " field.getValue()=" + field.getValue() +
+ " field.getValue().isConstant()=" +
+ (field.getValue() != null ? field.getValue().isConstant() : false));
+ System.err.flush();
return constantPrefix
&& field.isFinal()
&& field.getValue() != null
And I made a simpler test case:
bash$ cat x.java
public interface x {
int aa = y.b + 1;
int aaa = aa + 1;
}
bash$ cat y.java
public class y {
static final int b = 3;
public static void main(String[] args) {
int n = 0;
switch (n) {
case x.aa:
default:
System.out.println("OK");
}
}
}
As you see, int aaa in x is not used anywhere, but it is
essential: commenting out the definition of int aaa, you
will see no error.
Then kjc prints the following:
bash$ java at.dms.kjc.Main -v x.java y.java
[ start compilation in verbose mode ]
[ parsed x.java in 1,870 ms ]
[ parsed y.java in 280 ms ]
[ checked interfaces in 1,040 ms ]
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
## aa isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JAddExpression[JFieldAccessExpression[at.dms.kjc.JTypeNameExpression@4a63d8, b], JIntLiteral[1]] field.getValue().isConstant()=false
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
## aa isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JAddExpression[JFieldAccessExpression[at.dms.kjc.JTypeNameExpression@4a63d8, b], JIntLiteral[1]] field.getValue().isConstant()=false
[ checked body of x.java in 0 ms ]
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JIntLiteral[3] field.getValue().isConstant()=true
## aa isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JAddExpression[JFieldAccessExpression[at.dms.kjc.JTypeNameExpression@4a63d8, b = y/b], JIntLiteral[1]] field.getValue().isConstant()=false
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JIntLiteral[3] field.getValue().isConstant()=true
## aa isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JAddExpression[JFieldAccessExpression[at.dms.kjc.JTypeNameExpression@4a63d8, b = y/b], JIntLiteral[1]] field.getValue().isConstant()=false
y.java:6: error:Switch label must be constant [JLS 14.10]
[ checked body of y.java in 50 ms ]
As I said before, the sequence of input files is important.
Placing y.java before x.java, you will see no error:
bash$ java at.dms.kjc.Main -v y.java x.java
[ start compilation in verbose mode ]
[ parsed y.java in 2,150 ms ]
[ parsed x.java in 50 ms ]
[ checked interfaces in 1,320 ms ]
## b isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JIntLiteral[3] field.getValue().isConstant()=true
## aa isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JIntLiteral[4] field.getValue().isConstant()=true
## aa isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=JIntLiteral[4] field.getValue().isConstant()=true
## out isConstant(): constantPrefix = true field.isFinal()=true field.getValue()=null field.getValue().isConstant()=false
[ checked body of y.java in 770 ms ]
[ checked body of x.java in 0 ms ]
[ optimized and generated y in 1,310 ms ]
[ optimized and generated x in 330 ms ]
[ compilation ended ]
Thank you.