From commits-return-9371-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Fri Oct 18 09:30:23 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 161B41804BB for ; Fri, 18 Oct 2019 11:30:22 +0200 (CEST) Received: (qmail 46438 invoked by uid 500); 18 Oct 2019 09:30:22 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 46429 invoked by uid 99); 18 Oct 2019 09:30:22 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Oct 2019 09:30:22 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 516F780936; Fri, 18 Oct 2019 09:30:22 +0000 (UTC) Date: Fri, 18 Oct 2019 09:30:22 +0000 To: "commits@groovy.apache.org" Subject: [groovy] branch master updated: GROOVY-6996: adjust 6834 workaround to apply to synthetic variables only MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <157139102218.19954.2920136935732395677@gitbox.apache.org> From: sunlan@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: groovy X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 4eef1ae8dc0d79ac5961d967f84bb31d38b836f4 X-Git-Newrev: 4e0ed234e9530f5bbaea89111b26ab0f83eb4d5f X-Git-Rev: 4e0ed234e9530f5bbaea89111b26ab0f83eb4d5f X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git The following commit(s) were added to refs/heads/master by this push: new 4e0ed23 GROOVY-6996: adjust 6834 workaround to apply to synthetic variables only 4e0ed23 is described below commit 4e0ed234e9530f5bbaea89111b26ab0f83eb4d5f Author: Eric Milles AuthorDate: Tue Oct 15 13:32:11 2019 -0500 GROOVY-6996: adjust 6834 workaround to apply to synthetic variables only --- .../groovy/classgen/VariableScopeVisitor.java | 17 +++---- src/test/groovy/bugs/Groovy6996.groovy | 59 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java index 12ae1ed..e6ffc6f 100644 --- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java +++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java @@ -558,22 +558,21 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport { currentScope.setInStaticContext(false); for (MethodNode method : innerClass.getMethods()) { Parameter[] parameters = method.getParameters(); - if (parameters.length == 0) parameters = null; // null means no implicit "it" + if (parameters.length == 0) + parameters = null; // null means no implicit "it" ClosureExpression cl = new ClosureExpression(parameters, method.getCode()); visitClosureExpression(cl); } for (FieldNode field : innerClass.getFields()) { - final Expression expression = field.getInitialExpression(); + Expression expression = field.getInitialExpression(); pushState(field.isStatic()); if (expression != null) { - if (expression instanceof VariableExpression) { - VariableExpression vexp = (VariableExpression) expression; - if (vexp.getAccessedVariable() instanceof Parameter) { - // workaround for GROOVY-6834: accessing a parameter which is not yet seen in scope - popState(); - continue; - } + if (expression.isSynthetic() && expression instanceof VariableExpression && + ((VariableExpression) expression).getAccessedVariable() instanceof Parameter) { + // GROOVY-6834: accessing a parameter which is not yet seen in scope + popState(); + continue; } expression.visit(this); } diff --git a/src/test/groovy/bugs/Groovy6996.groovy b/src/test/groovy/bugs/Groovy6996.groovy new file mode 100644 index 0000000..ae0f209 --- /dev/null +++ b/src/test/groovy/bugs/Groovy6996.groovy @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package groovy.bugs + +import groovy.transform.CompileStatic +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript + +@CompileStatic +final class Groovy6996 { + + @Test + void testAnonInnerClassLocalVariableAccess() { + assertScript ''' + class C { + interface I { + } + static main(args) { + def var = args + new I() { + def prop = var + } + } + } + ''' + } + + @Test + void testAnonInnerClassParameterAccess() { + assertScript ''' + class C { + interface I { + } + static main(args) { + new I() { + def prop = args // MissingPropertyException: No such property: args for class: C + } + } + } + ''' + } +}