Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-6168 Retain prefix when parsing types in JVM signatures
When reading Java classfiles, the generic signatures are used to construct the corresponding Scala type signatures. In the enclosed test case, the field `SomeClass.f` had the JVM signature: LContext<LSomeClass;>.Field<Ljava.lang.Integer;>; The parser first (correctly) parsed the prefix as `Context[SomeClass]`. It then looked up the type symbol for `Field` in that that type. It then discarded the parsed prefix, and instead used the prefix from the info of the type symbol: `Context[ParentType]`. This commit changes the signature parser after the first `.` to use the result of prior parsing as the prefix. I've also included a test case with Java static inner classes, which don't require any special treatment.
- Loading branch information
Showing
10 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public class Context<ParentType> { | ||
private ParentType parent; | ||
|
||
public Context() {} | ||
|
||
public ParentType getParent() { | ||
return parent; | ||
} | ||
|
||
public void setParent(ParentType parent) { | ||
this.parent = parent; | ||
} | ||
|
||
public Field<Integer> intField() { | ||
return new Field<Integer>() { | ||
@Override | ||
public Integer get() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public ParentType set(Integer t) { | ||
return parent; | ||
} | ||
}; | ||
} | ||
|
||
public abstract class Field<T> { //Note this is a path dependent type | ||
|
||
public abstract T get(); | ||
|
||
public abstract ParentType set(T t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class JavaTest { | ||
public static void main(String[] args) { | ||
SomeClass a = new SomeClass(); | ||
SomeClass2 a2 = new SomeClass2(); | ||
SomeClass b = a.f.set(23).f.set(23); | ||
SomeClass2 b2 = a2.f.set(23).f.set(23); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class SomeClass { | ||
private final Context<SomeClass> context = new Context<SomeClass>(); | ||
{ | ||
context.setParent(this); | ||
} | ||
|
||
public final Context<SomeClass>.Field<Integer> f = context.intField(); | ||
|
||
public SomeClass() { | ||
f.set(23).f.set(23); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class SomeClass2 { | ||
private final Context<SomeClass2> context = new Context<SomeClass2>(); | ||
{ | ||
context.setParent(this); | ||
} | ||
|
||
public final Context<SomeClass2>.Field<Integer> f = context.intField(); | ||
|
||
public SomeClass2() { | ||
f.set(23).f.set(23); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
object Test extends App { | ||
JavaTest.main(null) | ||
|
||
var a1 : SomeClass = new SomeClass | ||
var a2 : SomeClass2 = new SomeClass2 | ||
//import language.implicitConversions | ||
//implicit def setParentType2SomeClass(x:Any) = x.asInstanceOf[SomeClass] | ||
//implicit def setParentType2SomeClass2(x:Any) = x.asInstanceOf[SomeClass2] | ||
//var b : SomeClass = a.f.set(23).asInstanceOf[SomeClass].f.set(23).asInstanceOf[SomeClass] | ||
//var b2 : SomeClass2 = a2.f.set(23).asInstanceOf[SomeClass2].f.set(23).asInstanceOf[SomeClass2] | ||
var b1 : SomeClass = a1.f.set(23).f.set(23) | ||
var b2 : SomeClass2 = a2.f.set(23).f.set(23) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public class Context<ParentType> { | ||
private ParentType parent; | ||
|
||
public Context() {} | ||
|
||
public ParentType getParent() { | ||
return parent; | ||
} | ||
|
||
public void setParent(ParentType parent) { | ||
this.parent = parent; | ||
} | ||
|
||
public Field<Integer> intField() { | ||
return new Field<Integer>() { | ||
@Override | ||
public Integer get() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public ParentType set(Integer t) { | ||
return parent; | ||
} | ||
}; | ||
} | ||
|
||
public static abstract class Field<T> { | ||
|
||
public abstract T get(); | ||
|
||
public abstract Object set(T t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class JavaTest { | ||
public static void main(String[] args) { | ||
SomeClass a = new SomeClass(); | ||
Object b = a.f.set(23); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class SomeClass { | ||
private final Context<SomeClass> context = new Context<SomeClass>(); | ||
{ | ||
context.setParent(this); | ||
} | ||
|
||
public final Context.Field<Integer> f = context.intField(); | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
object Test extends App { | ||
JavaTest.main(null) | ||
|
||
var a1 : SomeClass = new SomeClass | ||
var b1 : Object = a1.f.set(23) | ||
} |