Skip to content

Commit

Permalink
GROOVY-5859: Invalid generics are generated in stubs in super constru…
Browse files Browse the repository at this point in the history
…ctor calls
  • Loading branch information
melix committed Apr 11, 2013
1 parent dbdce6d commit 33f3b62
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/org/codehaus/groovy/ast/GenericsType.java
Expand Up @@ -62,7 +62,7 @@ public String toString() {

private String toString(Set<String> visited) {
if (placeholder) visited.add(name);
String ret = (type == null || placeholder || wildcard) ? name : genericsBounds(type, visited);
String ret = wildcard?"?":((type == null || placeholder) ? name : genericsBounds(type, visited));
if (upperBounds != null) {
ret += " extends ";
for (int i = 0; i < upperBounds.length; i++) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
Expand Up @@ -404,12 +404,19 @@ private void printConstructor(PrintWriter out, ClassNode clazz, ConstructorNode

private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) {
ClassNode type = node.getDeclaringClass();
ClassNode superType = type.getSuperClass();
ClassNode superType = type.getUnresolvedSuperClass();

for (ConstructorNode c : superType.getDeclaredConstructors()) {
// Only look at things we can actually call
if (c.isPublic() || c.isProtected()) {
return c.getParameters();
Parameter[] parameters = c.getParameters();
// workaround for GROOVY-5859: remove generic type info
Parameter[] copy = new Parameter[parameters.length];
for (int i = 0; i < copy.length; i++) {
Parameter orig = parameters[i];
copy[i] = new Parameter(orig.getOriginType().getPlainNodeReference(), orig.getName());
}
return copy;
}
}

Expand Down
@@ -0,0 +1,46 @@
/*
* Copyright 2003-2013 the original author or authors.
*
* Licensed 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.tools.stubgenerator

class Groovy5859Bug extends StringSourcesStubTestCase {
@Override
Map<String, String> provideSources() {
['TaggedsMap.groovy': '''class TaggedsMap extends TreeMap {
TaggedsMap() { super() }
TaggedsMap(Comparator comparator) { super(comparator)}
TaggedsMap(Map m) {
super()
putAll( m)
}
TaggedsMap(SortedMap m) {
super()
putAll (m)
}
}''',
'Blah.java': '''public class Blah { TaggedsMap map; }''']
}

@Override
void verifyStubs() {
def stubSource = stubJavaSourceFor('TaggedsMap')
assert stubSource.contains('super ((java.util.SortedMap)null);')
}
}

0 comments on commit 33f3b62

Please sign in to comment.