[
https://issues.apache.org/jira/browse/GROOVY-12131?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18095135#comment-18095135
]
ASF GitHub Bot commented on GROOVY-12131:
-----------------------------------------
blackdrag commented on code in PR #2666:
URL: https://github.com/apache/groovy/pull/2666#discussion_r3555840108
##########
src/test/groovy/org/codehaus/groovy/control/OptimizerVisitorTest.groovy:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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 org.codehaus.groovy.control
+
+import org.codehaus.groovy.ast.ClassHelper
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.codehaus.groovy.ast.stmt.Statement
+import org.junit.jupiter.api.Test
+import org.objectweb.asm.Opcodes
+
+import static org.codehaus.groovy.ast.tools.GeneralUtils.block
+import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt
+
+/**
+ * GROOVY-12131: constant caching communicates the assigned {@code $const$}
field name by
+ * mutating the {@link ConstantExpression}, which assumes each node is
reachable from exactly
+ * one class. An AST transform that aliases a node into a second class makes
the classes
+ * overwrite each other's stamp, so one class silently reads the wrong cached
constant at
+ * runtime. The visitor now warns when it re-stamps a node with a different
field name.
+ */
+class OptimizerVisitorTest {
Review Comment:
I think there should be also a script based test of the fix. This is AST
level only and may be subject to change, a simple script failing before and now
being correct exhibits the problem and will be kept in case we solve this
differently in the future
> OptimizerVisitor: detect constant nodes shared across classes
> -------------------------------------------------------------
>
> Key: GROOVY-12131
> URL: https://issues.apache.org/jira/browse/GROOVY-12131
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)