Skip to content

Commit 73bfead

Browse files
authored
Merge pull request #11980 from dotty-staging/fix-11977
When simplifying match types, ensure fully defined before reducing
2 parents 73d056a + 5fea7ed commit 73bfead

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ object TypeOps:
139139
case tp1 => tp1
140140
}
141141
case tp: AppliedType =>
142+
tp.tycon match
143+
case tycon: TypeRef if tycon.info.isInstanceOf[MatchAlias] =>
144+
isFullyDefined(tp, ForceDegree.all)
145+
case _ =>
142146
val normed = tp.tryNormalize
143147
if normed.exists then normed else tp.map(simplify(_, theMap))
144148
case tp: TypeParamRef =>

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,10 +1816,12 @@ object Types {
18161816
/** A simplified version of this type which is equivalent wrt =:= to this type.
18171817
* This applies a typemap to the type which (as all typemaps) follows type
18181818
* variable instances and reduces typerefs over refined types. It also
1819-
* re-evaluates all occurrences of And/OrType with &/| because
1820-
* what was a union or intersection of type variables might be a simpler type
1821-
* after the type variables are instantiated. Finally, it
1822-
* maps poly params in the current constraint set back to their type vars.
1819+
*
1820+
* - re-evaluates all occurrences of And/OrType with &/| because
1821+
* what was a union or intersection of type variables might be a simpler type
1822+
* after the type variables are instantiated.
1823+
* - maps poly params in the current constraint set back to their type vars.
1824+
* - forces match types to be fully defined and tries to normalize them.
18231825
*
18241826
* NOTE: Simplifying an intersection type might change its erasure (for
18251827
* example, the Java erasure of `Object & Serializable` is `Object`,

compiler/test-resources/repl/i5218

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ val tuple: (Int, String, Long) = (1,2,3)
33
scala> 0.0 *: tuple
44
val res0: (Double, Int, String, Long) = (0.0,1,2,3)
55
scala> tuple ++ tuple
6-
val res1: Int *: scala.Tuple.Concat[(String, Long), tuple.type] = (1,2,3,1,2,3)
6+
val res1: Int *: String *: Long *:
7+
scala.Tuple.Concat[scala.Tuple$package.EmptyTuple.type, tuple.type] = (1,2,3,1,2,3)

tests/pos/i11977.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test:
2+
3+
def add0(a : (Int, String), b : (Int, String)): Int =
4+
val x = 3
5+
x + b(0)
6+
7+
def add(a : (Int, String), b : (Int, String)) : (Int, String) = (a(0) + b(0), a(1) + b(1))

0 commit comments

Comments
 (0)