Constant folding does not work for enum constants

Issue #191 resolved
Jesper Öqvist created an issue

ExtendJ 8.0.1-157-ge916427 Java SE 8

Constant expressions that use enum constants cause ExtendJ to crash when ExtendJ tries to fold the constant expression.

The following test case causes ExtendJ to crash:

import static runtime.Test.*;

public class Test {
  public static enum CatType {

  public static final String cat1 = "Cat in the " + CatType.HAT;

An UnsupportedOperationException is thrown:

    [junit] Compilation failed when expected to pass:
    [junit] Fatal exception:
    [junit] java.lang.UnsupportedOperationException: ConstantExpression operation constant not supported for type org.extendj.ast.EnumInstanceE
    [junit]     at org.extendj.ast.Expr.constant(
    [junit]     at org.extendj.ast.VarAccess.constant(
    [junit]     at org.extendj.ast.AbstractDot.constant(
    [junit]     at org.extendj.ast.AddExpr.constant(
    [junit]     at org.extendj.ast.ConstantValueAttribute.<init>(
    [junit]     at org.extendj.ast.FieldDeclarator.refined_Attributes_FieldDeclarator_attributes(
    [junit]     at org.extendj.ast.FieldDeclarator.refined_AnnotationsCodegen_FieldDeclarator_attributes(
    [junit]     at org.extendj.ast.FieldDeclarator.attributes_compute(
    [junit]     at org.extendj.ast.FieldDeclarator.attributes(
    [junit]     at org.extendj.ast.ClassDecl.generateClassfile(

Comments (1)

  1. Jesper Öqvist reporter

    Fix error in enum constant folding

    This fixes a crash when attempting to fold a constant expression including an enum constant.

    fixes #191 (bitbucket)

    → <<cset 3361427b2dcd>>

  2. Log in to comment