File tree Expand file tree Collapse file tree 5 files changed +21
-1
lines changed
compiler/src/dotty/tools/dotc/core
tests/run/java-intersection Expand file tree Collapse file tree 5 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,8 @@ object TypeOps:
156
156
case _ : AppliedType | _ : MatchType =>
157
157
val normed = tp.tryNormalize
158
158
if (normed.exists) normed else mapOver
159
+ case tp : MethodicType =>
160
+ tp // See documentation of `Types#simplified`
159
161
case _ =>
160
162
mapOver
161
163
}
Original file line number Diff line number Diff line change @@ -1667,6 +1667,13 @@ object Types {
1667
1667
* what was a union or intersection of type variables might be a simpler type
1668
1668
* after the type variables are instantiated. Finally, it
1669
1669
* maps poly params in the current constraint set back to their type vars.
1670
+ *
1671
+ * NOTE: Simplifying an intersection type might change its erasure (for
1672
+ * example, the Java erasure of `Object & Serializable` is `Object`,
1673
+ * but its simplification is `Serializable`). This means that simplification
1674
+ * should never be used in a `MethodicType`, because that could
1675
+ * lead to a different `signature`. Since this isn't very useful anyway,
1676
+ * this method handles this by never simplifying inside a `MethodicType`.
1670
1677
*/
1671
1678
def simplified (implicit ctx : Context ): Type = TypeOps .simplify(this , null )
1672
1679
Original file line number Diff line number Diff line change @@ -434,7 +434,8 @@ class ClassfileParser(
434
434
if (sig(index) != ':' ) // guard against empty class bound
435
435
ts += objToAny(sig2type(tparams, skiptvs))
436
436
}
437
- TypeBounds .upper(ts.foldLeft(NoType : Type )(_ & _) orElse defn.AnyType )
437
+ val bound = if ts.isEmpty then defn.AnyType else ts.reduceLeft(AndType .apply)
438
+ TypeBounds .upper(bound)
438
439
}
439
440
440
441
var tparams = classTParams
Original file line number Diff line number Diff line change
1
+ public class A_1 {
2
+ public <T extends Object & java .io .Serializable > void foo (T x ) {}
3
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def main (args : Array [String ]): Unit = {
3
+ val a = new A_1
4
+ val x = new java.io.Serializable {}
5
+ a.foo(x)
6
+ }
7
+ }
You can’t perform that action at this time.
0 commit comments