Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/groovy into parrot
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d21ddc7a Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d21ddc7a Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d21ddc7a Branch: refs/heads/parrot Commit: d21ddc7abe062ee643b5d6db8e209a9da50446fe Parents: a9c7046 01fdb70 Author: sunlan <sun...@apache.org> Authored: Wed Feb 8 12:11:16 2017 +0800 Committer: sunlan <sun...@apache.org> Committed: Wed Feb 8 12:11:58 2017 +0800 ---------------------------------------------------------------------- build.gradle | 2 +- gradle/pomconfigurer.gradle | 3 + src/main/groovy/util/logging/Commons.java | 1 + src/main/groovy/util/logging/Log.java | 1 + src/main/groovy/util/logging/Log4j.java | 1 + src/main/groovy/util/logging/Log4j2.java | 1 + src/main/groovy/util/logging/Slf4j.java | 1 + .../codehaus/groovy/ast/tools/GeneralUtils.java | 4 + .../groovy/classgen/AnnotationVisitor.java | 31 ++- .../asm/sc/StaticTypesCallSiteWriter.java | 14 +- .../groovy/runtime/StringGroovyMethods.java | 5 + .../stc/StaticTypeCheckingVisitor.java | 275 +++++-------------- src/spec/doc/core-syntax.adoc | 2 +- src/test/gls/annotations/AnnotationTest.groovy | 4 - src/test/groovy/bugs/Groovy8026Bug.groovy | 35 +++ src/test/groovy/bugs/Groovy8030Bug.groovy | 34 +++ .../classgen/asm/sc/bugs/Groovy8069Bug.groovy | 55 ++++ .../src/main/java/groovy/sql/Sql.java | 15 +- 18 files changed, 256 insertions(+), 228 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/d21ddc7a/build.gradle ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/d21ddc7a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java ---------------------------------------------------------------------- diff --cc src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java index 37bfe88,727739d..d77316a --- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java +++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java @@@ -632,18 -631,23 +631,23 @@@ public class StaticTypesCallSiteWriter } // now try with flow type instead of declaration type rType = receiver.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); + if (receiver instanceof VariableExpression && receiver.getNodeMetaData().isEmpty()) { + // TODO: can STCV be made smarter to avoid this check? + VariableExpression ve = (VariableExpression) ((VariableExpression)receiver).getAccessedVariable(); + rType = ve.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); + } - if (rType!=null && trySubscript(receiver, message, arguments, rType, aType)) { + if (rType!=null && trySubscript(receiver, message, arguments, rType, aType, safe)) { return; } // todo: more cases throw new GroovyBugError( - "At line "+receiver.getLineNumber() + " column " + receiver.getColumnNumber() + "\n" + - "On receiver: "+receiver.getText() + " with message: "+message+" and arguments: "+arguments.getText()+"\n"+ - "This method should not have been called. Please try to create a simple example reproducing this error and file" + - "a bug report at https://issues.apache.org/jira/browse/GROOVY"); + "At line " + receiver.getLineNumber() + " column " + receiver.getColumnNumber() + "\n" + + "On receiver: " + receiver.getText() + " with message: " + message + " and arguments: " + arguments.getText() + "\n" + + "This method should not have been called. Please try to create a simple example reproducing\n" + + "this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY"); } - private boolean trySubscript(final Expression receiver, final String message, final Expression arguments, ClassNode rType, final ClassNode aType) { + private boolean trySubscript(final Expression receiver, final String message, final Expression arguments, ClassNode rType, final ClassNode aType, boolean safe) { if (getWrapper(rType).isDerivedFrom(Number_TYPE) && getWrapper(aType).isDerivedFrom(Number_TYPE)) { if ("plus".equals(message) || "minus".equals(message) || "multiply".equals(message) || "div".equals(message)) { http://git-wip-us.apache.org/repos/asf/groovy/blob/d21ddc7a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java ---------------------------------------------------------------------- diff --cc src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 006e082,0f49976..a2f93f0 --- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@@ -693,11 -580,11 +583,11 @@@ public class StaticTypeCheckingVisitor if (!isPrimitiveType(lType)) rType = UNKNOWN_PARAMETER_TYPE; // primitive types should be ignored as they will result in another failure } - BinaryExpression reversedBinaryExpression = new BinaryExpression(rightExpression, expression.getOperation(), leftExpression); + BinaryExpression reversedBinaryExpression = binX(rightExpression, expression.getOperation(), leftExpression); - ClassNode resultType = op==KEYWORD_IN + ClassNode resultType = (op==KEYWORD_IN || op==COMPARE_NOT_IN) ?getResultType(rType,op,lType,reversedBinaryExpression) :getResultType(lType, op, rType, expression); - if (op==KEYWORD_IN) { + if (op==KEYWORD_IN || op==COMPARE_NOT_IN) { // in case of the "in" operator, the receiver and the arguments are reversed // so we use the reversedExpression and get the target method from it storeTargetMethod(expression, (MethodNode) reversedBinaryExpression.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET)); @@@ -1202,7 -1080,7 +1083,7 @@@ * * @param node the class node for which we will try to find a matching constructor * @param arguments the constructor arguments -- * @deprecated use {@link #checkGroovyStyleConstructor(org.codehaus.groovy.ast.ClassNode, org.codehaus.groovy.ast.ClassNode[], org.codehaus.groovy.ast.ASTNode)} )} ++ * @deprecated use {@link #checkGroovyStyleConstructor(ClassNode, ClassNode[], ASTNode)} )} */ @Deprecated protected void checkGroovyStyleConstructor(final ClassNode node, final ClassNode[] arguments) { @@@ -2224,13 -2098,13 +2101,13 @@@ return; } if (!extension.beforeVisitMethod(node)) { -- ErrorCollector collector = (ErrorCollector) node.getNodeMetaData(ERROR_COLLECTOR); -- if (collector != null) { -- typeCheckingContext.getErrorCollector().addCollectorContents(collector); -- } else { -- startMethodInference(node, typeCheckingContext.getErrorCollector()); -- } -- node.removeNodeMetaData(ERROR_COLLECTOR); ++ ErrorCollector collector = (ErrorCollector) node.getNodeMetaData(ERROR_COLLECTOR); ++ if (collector != null) { ++ typeCheckingContext.getErrorCollector().addCollectorContents(collector); ++ } else { ++ startMethodInference(node, typeCheckingContext.getErrorCollector()); ++ } ++ node.removeNodeMetaData(ERROR_COLLECTOR); } extension.afterVisitMethod(node); } @@@ -2459,13 -2333,13 +2336,13 @@@ * This method is responsible for performing type inference on closure argument types whenever code like this is * found: <code>foo.collect { it.toUpperCase() }</code>. * In this case, the type checker tries to find if the <code>collect</code> method has its {@link Closure} argument -- * annotated with {@link groovy.transform.stc.ClosureParams}. If yes, then additional type inference can be performed ++ * annotated with {@link ClosureParams}. If yes, then additional type inference can be performed * and the type of <code>it</code> may be inferred. * * @param receiver * @param arguments * @param expression a closure expression for which the argument types should be inferred -- * @param param the parameter where to look for a {@link groovy.transform.stc.ClosureParams} annotation. ++ * @param param the parameter where to look for a {@link ClosureParams} annotation. * @param selectedMethod the method accepting a closure */ protected void inferClosureParameterTypes(final ClassNode receiver, final Expression arguments, final ClosureExpression expression, final Parameter param, final MethodNode selectedMethod) { @@@ -2738,7 -2612,7 +2615,7 @@@ /** * Given a GenericsType instance, returns a ClassNode which can be used as an inferred type. -- * @param genericsType a {@link org.codehaus.groovy.ast.GenericsType} representing either a type, a placeholder or a wildcard ++ * @param genericsType a {@link GenericsType} representing either a type, a placeholder or a wildcard * @return a class node usable as an inferred type */ private static ClassNode createUsableClassNodeFromGenericsType(final GenericsType genericsType) { @@@ -3205,7 -3075,7 +3078,7 @@@ * @param directMethodCallCandidate a method selected by the type checker * @param receiver the receiver of the method call *@param args the arguments of the method call -- * @param returnType the original return type, as inferred by the type checker @return fixed return type if the selected method is {@link org.codehaus.groovy.runtime.DefaultGroovyMethods#withTraits(Object, Class[]) withTraits} ++ * @param returnType the original return type, as inferred by the type checker @return fixed return type if the selected method is {@link DefaultGroovyMethods#withTraits(Object, Class[]) withTraits} */ private static ClassNode adjustWithTraits(final MethodNode directMethodCallCandidate, final ClassNode receiver, final ClassNode[] args, final ClassNode returnType) { if (directMethodCallCandidate instanceof ExtensionMethodNode) { @@@ -4896,7 -4758,7 +4761,7 @@@ /** * Returns a wrapped type if, and only if, the provided class node is a primitive type. -- * This method differs from {@link ClassHelper#getWrapper(org.codehaus.groovy.ast.ClassNode)} as it will ++ * This method differs from {@link ClassHelper#getWrapper(ClassNode)} as it will * return the same instance if the provided type is not a generic type. * * @param type