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 2021/01/27 14:52:02 UTC
[groovy] branch GROOVY-9914 created (now 105d4f3)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a change to branch GROOVY-9914
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at 105d4f3 GROOVY-9914: DGM: add return type parameters for collectEntries variant
This branch includes the following new commits:
new 105d4f3 GROOVY-9914: DGM: add return type parameters for collectEntries variant
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[groovy] 01/01: GROOVY-9914: DGM: add return type parameters for
collectEntries variant
Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY-9914
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 105d4f3225dcc71504ab31e23b2c3e785ef1dccf
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Jan 27 08:51:39 2021 -0600
GROOVY-9914: DGM: add return type parameters for collectEntries variant
---
.../org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 10 +++++-----
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 12 ++++++++++++
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 3fa47b6..e44fccd 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -3862,8 +3862,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @see #collect(Map, Collection, Closure)
* @since 1.7.9
*/
- public static <K, V, S, T> Map<K, V> collectEntries(Map<S, T> self, Map<K, V> collector, @ClosureParams(MapEntryOrKeyValue.class) Closure<?> transform) {
- for (Map.Entry<S, T> entry : self.entrySet()) {
+ public static <K, V, X, Y> Map<K, V> collectEntries(Map<X, Y> self, Map<K, V> collector, @ClosureParams(MapEntryOrKeyValue.class) Closure<?> transform) {
+ for (Map.Entry<X, Y> entry : self.entrySet()) {
addEntry(collector, callClosureForMapEntry(transform, entry));
}
return collector;
@@ -3889,8 +3889,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @see #collect(Map, Collection, Closure)
* @since 1.7.9
*/
- public static <K,V> Map<?, ?> collectEntries(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<?> transform) {
- return collectEntries(self, createSimilarMap(self), transform);
+ public static <K, V, X, Y> Map<K, V> collectEntries(Map<X, Y> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<?> transform) {
+ return collectEntries(self, (Map) createSimilarMap(self), transform);
}
/**
@@ -3928,7 +3928,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @see #collectEntries(Iterator, Closure)
* @since 1.8.7
*/
- public static <K,V,E> Map<K, V> collectEntries(Iterable<E> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<?> transform) {
+ public static <K, V, E> Map<K, V> collectEntries(Iterable<E> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<?> transform) {
return collectEntries(self.iterator(), transform);
}
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 4028800..5a13430 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -280,6 +280,18 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
''', 'Number'
}
+ // GROOVY-9914
+ void testAssignmentShouldWorkForParameterizedMap() {
+ assertScript '''
+ Map test(Map<String,String> one) {
+ Map<String,Integer> two = one.collectEntries { k,v ->
+ [(k): v.hashCode()]
+ }
+ }
+ assert test(foo:'bar').containsKey('foo')
+ '''
+ }
+
// GROOVY-9555
void testAssignmentShouldWorkForProperUpperBound() {
assertScript '''