@@ -889,7 +889,11 @@ public void visitAnnotatedType(JCAnnotatedType tree) {
889
889
} else {
890
890
//type test pattern:
891
891
int varPos = token .pos ;
892
- JCVariableDecl var = variableDeclaratorRest (varPos , mods , e , identOrUnderscore (), false , null , false , false , true );
892
+ Name name = identOrUnderscore ();
893
+ if (Feature .UNNAMED_VARIABLES .allowedInSource (source ) && name == names .underscore ) {
894
+ name = names .empty ;
895
+ }
896
+ JCVariableDecl var = toP (F .at (varPos ).VarDef (mods , name , e , null ));
893
897
if (e == null ) {
894
898
var .startPos = pos ;
895
899
if (var .name == names .underscore && !allowVar ) {
@@ -3618,7 +3622,7 @@ protected <T extends ListBuffer<? super JCVariableDecl>> T variableDeclaratorsRe
3618
3622
T vdefs ,
3619
3623
boolean localDecl )
3620
3624
{
3621
- JCVariableDecl head = variableDeclaratorRest (pos , mods , type , name , reqInit , dc , localDecl , false , false );
3625
+ JCVariableDecl head = variableDeclaratorRest (pos , mods , type , name , reqInit , dc , localDecl , false );
3622
3626
vdefs .append (head );
3623
3627
while (token .kind == COMMA ) {
3624
3628
// All but last of multiple declarators subsume a comma
@@ -3633,7 +3637,7 @@ protected <T extends ListBuffer<? super JCVariableDecl>> T variableDeclaratorsRe
3633
3637
* ConstantDeclarator = Ident ConstantDeclaratorRest
3634
3638
*/
3635
3639
JCVariableDecl variableDeclarator (JCModifiers mods , JCExpression type , boolean reqInit , Comment dc , boolean localDecl ) {
3636
- return variableDeclaratorRest (token .pos , mods , type , identOrUnderscore (), reqInit , dc , localDecl , true , false );
3640
+ return variableDeclaratorRest (token .pos , mods , type , identOrUnderscore (), reqInit , dc , localDecl , true );
3637
3641
}
3638
3642
3639
3643
/** VariableDeclaratorRest = BracketsOpt ["=" VariableInitializer]
@@ -3643,13 +3647,13 @@ JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean r
3643
3647
* @param dc The documentation comment for the variable declarations, or null.
3644
3648
*/
3645
3649
JCVariableDecl variableDeclaratorRest (int pos , JCModifiers mods , JCExpression type , Name name ,
3646
- boolean reqInit , Comment dc , boolean localDecl , boolean compound , boolean isTypePattern ) {
3650
+ boolean reqInit , Comment dc , boolean localDecl , boolean compound ) {
3647
3651
boolean declaredUsingVar = false ;
3648
- type = bracketsOpt (type );
3649
3652
JCExpression init = null ;
3653
+ type = bracketsOpt (type );
3650
3654
3651
3655
if (Feature .UNNAMED_VARIABLES .allowedInSource (source ) && name == names .underscore ) {
3652
- if (!localDecl && ! isTypePattern ) {
3656
+ if (!localDecl ) {
3653
3657
log .error (DiagnosticFlag .SYNTAX , pos , Errors .UseOfUnderscoreNotAllowed );
3654
3658
}
3655
3659
name = names .empty ;
@@ -3668,38 +3672,32 @@ JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression ty
3668
3672
syntaxError (token .pos , Errors .Expected (EQ ));
3669
3673
}
3670
3674
3671
- JCVariableDecl result ;
3672
- if (!isTypePattern ) {
3673
- int startPos = Position .NOPOS ;
3674
- JCTree elemType = TreeInfo .innermostType (type , true );
3675
- if (elemType .hasTag (IDENT )) {
3676
- Name typeName = ((JCIdent ) elemType ).name ;
3677
- if (restrictedTypeNameStartingAtSource (typeName , pos , !compound && localDecl ) != null ) {
3678
- if (typeName != names .var ) {
3679
- reportSyntaxError (elemType .pos , Errors .RestrictedTypeNotAllowedHere (typeName ));
3680
- } else if (type .hasTag (TYPEARRAY ) && !compound ) {
3681
- //error - 'var' and arrays
3682
- reportSyntaxError (elemType .pos , Errors .RestrictedTypeNotAllowedArray (typeName ));
3683
- } else {
3684
- declaredUsingVar = true ;
3685
- if (compound )
3686
- //error - 'var' in compound local var decl
3687
- reportSyntaxError (elemType .pos , Errors .RestrictedTypeNotAllowedCompound (typeName ));
3688
- startPos = TreeInfo .getStartPos (mods );
3689
- if (startPos == Position .NOPOS )
3690
- startPos = TreeInfo .getStartPos (type );
3691
- //implicit type
3692
- type = null ;
3693
- }
3675
+ int startPos = Position .NOPOS ;
3676
+ JCTree elemType = TreeInfo .innermostType (type , true );
3677
+ if (elemType .hasTag (IDENT )) {
3678
+ Name typeName = ((JCIdent ) elemType ).name ;
3679
+ if (restrictedTypeNameStartingAtSource (typeName , pos , !compound && localDecl ) != null ) {
3680
+ if (typeName != names .var ) {
3681
+ reportSyntaxError (elemType .pos , Errors .RestrictedTypeNotAllowedHere (typeName ));
3682
+ } else if (type .hasTag (TYPEARRAY ) && !compound ) {
3683
+ //error - 'var' and arrays
3684
+ reportSyntaxError (elemType .pos , Errors .RestrictedTypeNotAllowedArray (typeName ));
3685
+ } else {
3686
+ declaredUsingVar = true ;
3687
+ if (compound )
3688
+ //error - 'var' in compound local var decl
3689
+ reportSyntaxError (elemType .pos , Errors .RestrictedTypeNotAllowedCompound (typeName ));
3690
+ startPos = TreeInfo .getStartPos (mods );
3691
+ if (startPos == Position .NOPOS )
3692
+ startPos = TreeInfo .getStartPos (type );
3693
+ //implicit type
3694
+ type = null ;
3694
3695
}
3695
3696
}
3696
- result = toP (F .at (pos ).VarDef (mods , name , type , init , declaredUsingVar ));
3697
- attach (result , dc );
3698
- result .startPos = startPos ;
3699
- } else {
3700
- result = toP (F .at (pos ).VarDef (mods , name , type , null ));
3701
3697
}
3702
-
3698
+ JCVariableDecl result = toP (F .at (pos ).VarDef (mods , name , type , init , declaredUsingVar ));
3699
+ attach (result , dc );
3700
+ result .startPos = startPos ;
3703
3701
return result ;
3704
3702
}
3705
3703
@@ -3843,12 +3841,12 @@ protected JCTree resource() {
3843
3841
if (token .kind == FINAL || token .kind == MONKEYS_AT ) {
3844
3842
JCModifiers mods = optFinal (0 );
3845
3843
JCExpression t = parseType (true );
3846
- return variableDeclaratorRest (token .pos , mods , t , identOrUnderscore (), true , null , true , false , false );
3844
+ return variableDeclaratorRest (token .pos , mods , t , identOrUnderscore (), true , null , true , false );
3847
3845
}
3848
3846
JCExpression t = term (EXPR | TYPE );
3849
3847
if (wasTypeMode () && LAX_IDENTIFIER .test (token .kind )) {
3850
3848
JCModifiers mods = F .Modifiers (0 );
3851
- return variableDeclaratorRest (token .pos , mods , t , identOrUnderscore (), true , null , true , false , false );
3849
+ return variableDeclaratorRest (token .pos , mods , t , identOrUnderscore (), true , null , true , false );
3852
3850
} else {
3853
3851
checkSourceLevel (Feature .EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES );
3854
3852
if (!t .hasTag (IDENT ) && !t .hasTag (SELECT )) {
0 commit comments