8294431: jshell reports error on initialisation of static final field of anonymous class
Reviewed-by: sundar
This commit is contained in:
parent
6e8f0387d6
commit
8e9cfeb17c
@ -523,8 +523,9 @@ class Eval {
|
||||
if (member.getKind() == Tree.Kind.VARIABLE) {
|
||||
VariableTree vt = (VariableTree) member;
|
||||
|
||||
if (vt.getInitializer() != null) {
|
||||
//for variables with initializer, explicitly move the initializer
|
||||
if (vt.getInitializer() != null &&
|
||||
!vt.getModifiers().getFlags().contains(Modifier.STATIC)) {
|
||||
//for instance variables with initializer, explicitly move the initializer
|
||||
//to the constructor after the captured variables as assigned
|
||||
//(the initializers would otherwise run too early):
|
||||
Range wholeVar = dis.treeToRange(vt);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8144903 8177466 8191842 8211694 8213725 8239536 8257236 8252409
|
||||
* @bug 8144903 8177466 8191842 8211694 8213725 8239536 8257236 8252409 8294431
|
||||
* @summary Tests for EvaluationState.variables
|
||||
* @library /tools/lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
@ -617,4 +617,8 @@ public class VariablesTest extends KullaTesting {
|
||||
assertEval("v.run()");
|
||||
}
|
||||
|
||||
public void varAnonymousClassAndStaticField() { //JDK-8294431
|
||||
assertEval("var obj = new Object() { public static final String msg = \"hello\"; };");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user