/*
 * Copyright 2014 Guidewire Software, Inc.
 */

package gw.internal.gosu.ir.transform.statement;

import gw.internal.gosu.ir.transform.ExpressionTransformer;
import gw.internal.gosu.ir.transform.TopLevelTransformationContext;
import gw.internal.gosu.parser.statements.NewStatement;
import gw.lang.ir.IRStatement;
import gw.lang.ir.expression.IRNewExpression;

/**
 */
public class NewStatementTransformer extends AbstractStatementTransformer<NewStatement>
{
  public static IRStatement compile( TopLevelTransformationContext cc, NewStatement stmt )
  {
    NewStatementTransformer compiler = new NewStatementTransformer( cc, stmt );
    return compiler.compile();
  }

  private NewStatementTransformer( TopLevelTransformationContext cc, NewStatement stmt )
  {
    super( cc, stmt );
  }

  @Override
  protected IRStatement compile_impl()
  {
    IRNewExpression newExpr = (IRNewExpression)ExpressionTransformer.compile( _stmt().getNewExpression(), _cc() );
    return buildNewExpression( newExpr );
  }
}
@@ -270,32 +270,64 @@
 s.NewStatement;%0A
+import gw.lang.ir.IRExpression;%0A
 import gw.lang.i
@@ -879,19 +879,16 @@
 %7B%0A    IR
-New
 Expressi
@@ -894,35 +894,15 @@
 ion 
-newE
+e
 xpr = 
-(IRNewExpression)
 Expr
@@ -973,39 +973,144 @@
     
-return buildNewExpression( newE
+if(expr instanceof IRNewExpression)%0A    %7B%0A      return buildNewExpression( (IRNewExpression) expr );%0A    %7D%0A    return buildMethodCall( e
 xpr 

Fix ClassCastException in compiler