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:
156156 case _ : AppliedType | _ : MatchType =>
157157 val normed = tp.tryNormalize
158158 if (normed.exists) normed else mapOver
159+ case tp : MethodicType =>
160+ tp // See documentation of `Types#simplified`
159161 case _ =>
160162 mapOver
161163 }
Original file line number Diff line number Diff line change @@ -1667,6 +1667,13 @@ object Types {
16671667 * what was a union or intersection of type variables might be a simpler type
16681668 * after the type variables are instantiated. Finally, it
16691669 * 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`.
16701677 */
16711678 def simplified (implicit ctx : Context ): Type = TypeOps .simplify(this , null )
16721679
Original file line number Diff line number Diff line change @@ -434,7 +434,8 @@ class ClassfileParser(
434434 if (sig(index) != ':' ) // guard against empty class bound
435435 ts += objToAny(sig2type(tparams, skiptvs))
436436 }
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)
438439 }
439440
440441 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