Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.7.5
-
Fix Version/s: 1.8.5, 2.0-beta-2, 1.7.11
-
Component/s: Compiler
-
Labels:None
-
Number of attachments :
Description
Simple file, A.groovy:
class A<String> { } class B { void foo(String s) {} }
groovyc A.groovy
javap -private B | grep foo
produces:
public void foo(java.lang.Object);
The 'String' is treated as a type parameter name. The reference 'String' in the foo method is mapped to this type parameter (clearly it shouldn't be) and when producing the code, String is erased to its upper bound of Object, hence foo(Object) in the bytecode.
Change it to this:
class A<T> {
}
class B {
void foo(String s) {}
}
and it produces what you expect:
public void foo(java.lang.String);
The problem is the genericParameterNames collection in the ResolveVisitor is never cleared, only augmented with new entries.
My solution that seems to work in groovy eclipse is to clear the parameter names at the end of visiting a classnode in ResolveVisitor. So at the end of
public void visitClass(ClassNode node) {
add
genericParameterNames.clear();
Issue Links
- is related to
-
GRECLIPSE-845
Can't run tests in project http://github.com/grails/inconsequential
-
Activity
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 1.8-beta-3 [ 16750 ] | |
| Fix Version/s | 1.7.X [ 15538 ] | |
| Fix Version/s | 1.8-beta-x [ 15750 ] | |
| Fix Version/s | 1.7.6 [ 16749 ] |
| Link |
This issue is related to |
| Assignee | Guillaume Laforge [ guillaume ] |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 1.7.X [ 15538 ] | |
| Fix Version/s | 1.8-beta-x [ 15750 ] | |
| Resolution | Fixed [ 1 ] |
| Resolution | Fixed [ 1 ] | |
| Status | Resolved [ 5 ] | Reopened [ 4 ] |
| Fix Version/s | 1.7.6 [ 16749 ] | |
| Fix Version/s | 1.8-beta-3 [ 16750 ] |
| Attachment | GROOVY-4457.patch [ 58038 ] |
| Assignee | Guillaume Laforge [ guillaume ] | Cedric Champeau [ melix ] |
| Status | Reopened [ 4 ] | Resolved [ 5 ] |
| Fix Version/s | 2.0-beta-2 [ 18072 ] | |
| Fix Version/s | 1.7.11 [ 17244 ] | |
| Fix Version/s | 1.8.5 [ 18071 ] | |
| Resolution | Fixed [ 1 ] |
| Status | Resolved [ 5 ] | Closed [ 6 ] |
I can later look into it a bit more to confirm but on a quick glance, I think that the solution suggested may not work when there are (anonymous)inner classes involved where outer class' generic parameter names remain valid inside the inner classes too.
We don't want to end visitClass() for an inner class and clear the genericParameterNames for the outer class as well.