You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/12/17 20:19:01 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10869: STC: primitive distance for `boolean`, `char`, etc.
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 26bcc52e8f GROOVY-10869: STC: primitive distance for `boolean`, `char`, etc.
26bcc52e8f is described below
commit 26bcc52e8ff172535c5abd79a996cf2e0407e0f9
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Dec 17 13:51:59 2022 -0600
GROOVY-10869: STC: primitive distance for `boolean`, `char`, etc.
---
.../groovy/transform/stc/StaticTypeCheckingSupport.java | 9 ++++++---
src/test/groovy/transform/stc/BugsSTCTest.groovy | 15 ++++++++++++---
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index a65df6d556..6471c667f6 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -921,8 +921,11 @@ public abstract class StaticTypeCheckingSupport {
return false;
}
- static int getPrimitiveDistance(ClassNode primA, ClassNode primB) {
- return Math.abs(NUMBER_TYPES.get(primA) - NUMBER_TYPES.get(primB));
+ private static final Integer NON_NUMBER_DEFAULT = 9; // GROOVY-10869: boolean, char, ...
+
+ static int getPrimitiveDistance(final ClassNode primA, final ClassNode primB) {
+ return Math.abs(NUMBER_TYPES.getOrDefault(primA, NON_NUMBER_DEFAULT)
+ - NUMBER_TYPES.getOrDefault(primB, NON_NUMBER_DEFAULT));
}
static int getDistance(final ClassNode receiver, final ClassNode compare) {
@@ -1524,7 +1527,7 @@ public abstract class StaticTypeCheckingSupport {
// the context we compare with in the end is the one of the callsite
// so far we specified the context of the method declaration only
// thus for each argument, we try to find the connected generics first
- Map<GenericsTypeName, GenericsType> connections = new LinkedHashMap<>();
+ Map<GenericsTypeName, GenericsType> connections = new HashMap<>();
extractGenericsConnections(connections, wrappedArgument, type);
// each new connection must comply with previous connections
diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy
index 15fedb03a7..dfc61454b0 100644
--- a/src/test/groovy/transform/stc/BugsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy
@@ -1187,12 +1187,21 @@ Printer
'''
}
+ // GROOVY-10869
+ void testBigDecimalCompareNullPointerException1() {
+ assertScript '''
+ class C<T> {
+ C(T x) { }
+ <T extends Short> T m(T x) { x }
+ }
+ C<Integer> obj = new C<Integer>(-76)
+ boolean cond = 5.0 > obj.m(new C<Integer>(95).m(null))
+ '''
+ }
+
// GROOVY-9999
void testMathSqrt() {
assertScript '''
- import groovy.transform.TypeChecked
-
- @TypeChecked
def test() {
Math.sqrt(Math.PI*2)
}