@@ -3421,13 +3421,14 @@ public Expression visitUnaryNotExprAlt(final UnaryNotExprAltContext ctx) {
3421
3421
3422
3422
@ Override
3423
3423
public CastExpression visitCastExprAlt (final CastExprAltContext ctx ) {
3424
- CastExpression cast = new CastExpression (
3425
- this .visitCastParExpression (ctx .castParExpression ()),
3426
- (Expression ) this .visit (ctx .expression ())
3427
- );
3424
+ Expression expr = (Expression ) this .visit (ctx .expression ());
3425
+ if (expr instanceof VariableExpression && ((VariableExpression ) expr ).isSuperExpression ()) {
3426
+ this .createParsingFailedException ("Cannot cast or coerce `super`" , ctx ); // GROOVY-9391
3427
+ }
3428
+ CastExpression cast = new CastExpression (this .visitCastParExpression (ctx .castParExpression ()), expr );
3428
3429
// GRECLIPSE add
3429
3430
Expression name = configureAST (new ConstantExpression (null ), ctx .castParExpression ().type ().primitiveType () != null
3430
- ? ctx .castParExpression ().type ().primitiveType () : ctx .castParExpression ().type ().classOrInterfaceType ());
3431
+ ? ctx .castParExpression ().type ().primitiveType () : ctx .castParExpression ().type ().classOrInterfaceType ());
3431
3432
cast .setNameStart (name .getStart ()); cast .setNameEnd (name .getEnd ());
3432
3433
// GRECLIPSE end
3433
3434
return configureAST (cast , ctx );
@@ -3545,45 +3546,39 @@ public Expression visitShiftExprAlt(final ShiftExprAltContext ctx) {
3545
3546
@ Override
3546
3547
public Expression visitRelationalExprAlt (final RelationalExprAltContext ctx ) {
3547
3548
switch (ctx .op .getType ()) {
3548
- case AS :
3549
- /* GRECLIPSE edit
3550
- return configureAST(
3551
- CastExpression.asExpression(this.visitType( ctx.type()), (Expression) this.visit(ctx.left)),
3552
- ctx);
3553
- */
3554
- CastExpression cast = CastExpression . asExpression ( visitType ( ctx . type ()), ( Expression ) visit ( ctx . left ));
3549
+ case AS :
3550
+ Expression expr = ( Expression ) this . visit ( ctx . left );
3551
+ if ( expr instanceof VariableExpression && (( VariableExpression ) expr ). isSuperExpression ()) {
3552
+ this . createParsingFailedException ( "Cannot cast or coerce `super`" , ctx ); // GROOVY-9391
3553
+ }
3554
+ CastExpression cast = CastExpression . asExpression ( this . visitType ( ctx . type ()), expr );
3555
+ // GRECLIPSE add
3555
3556
Expression name = configureAST (new ConstantExpression (null ), ctx .type ().primitiveType () != null
3556
- ? ctx .type ().primitiveType () : ctx .type ().classOrInterfaceType ());
3557
+ ? ctx .type ().primitiveType () : ctx .type ().classOrInterfaceType ());
3557
3558
cast .setNameStart (name .getStart ()); cast .setNameEnd (name .getEnd ());
3558
- return configureAST ( cast , ctx );
3559
- // GRECLIPSE end
3559
+ // GRECLIPSE end
3560
+ return configureAST ( cast , ctx );
3560
3561
3561
- case INSTANCEOF :
3562
- case NOT_INSTANCEOF :
3563
- ctx .type ().putNodeMetaData (IS_INSIDE_INSTANCEOF_EXPR , true );
3564
- return configureAST (
3565
- new BinaryExpression ((Expression ) this .visit (ctx .left ),
3566
- this .createGroovyToken (ctx .op ),
3567
- configureAST (new ClassExpression (this .visitType (ctx .type ())), ctx .type ())),
3568
- ctx );
3569
-
3570
- case LE :
3571
- case GE :
3572
- case GT :
3573
- case LT :
3574
- case IN :
3575
- case NOT_IN : {
3576
- if (ctx .op .getType () == IN || ctx .op .getType () == NOT_IN ) {
3577
- return this .createBinaryExpression (ctx .left , ctx .op , ctx .right , ctx );
3578
- }
3562
+ case INSTANCEOF :
3563
+ case NOT_INSTANCEOF :
3564
+ ctx .type ().putNodeMetaData (IS_INSIDE_INSTANCEOF_EXPR , Boolean .TRUE );
3565
+ return configureAST (
3566
+ new BinaryExpression (
3567
+ (Expression ) this .visit (ctx .left ),
3568
+ this .createGroovyToken (ctx .op ),
3569
+ configureAST (new ClassExpression (this .visitType (ctx .type ())), ctx .type ())),
3570
+ ctx );
3579
3571
3580
- return configureAST (
3581
- this .createBinaryExpression (ctx .left , ctx .op , ctx .right ),
3582
- ctx );
3583
- }
3572
+ case GT :
3573
+ case GE :
3574
+ case LT :
3575
+ case LE :
3576
+ case IN :
3577
+ case NOT_IN :
3578
+ return this .createBinaryExpression (ctx .left , ctx .op , ctx .right , ctx );
3584
3579
3585
- default :
3586
- throw createParsingFailedException ("Unsupported relational expression: " + ctx .getText (), ctx );
3580
+ default :
3581
+ throw this . createParsingFailedException ("Unsupported relational expression: " + ctx .getText (), ctx );
3587
3582
}
3588
3583
}
3589
3584
0 commit comments