Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: When simplifying match types, ensure fully defined before reducing #12068

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ object TypeOps:
case tp1 => tp1
}
case tp: AppliedType =>
tp.tycon match
case tycon: TypeRef if tycon.info.isInstanceOf[MatchAlias] =>
isFullyDefined(tp, ForceDegree.all)
case _ =>
val normed = tp.tryNormalize
if normed.exists then normed else tp.map(simplify(_, theMap))
case tp: TypeParamRef =>
Expand Down
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1816,10 +1816,12 @@ object Types {
/** A simplified version of this type which is equivalent wrt =:= to this type.
* This applies a typemap to the type which (as all typemaps) follows type
* variable instances and reduces typerefs over refined types. It also
* re-evaluates all occurrences of And/OrType with &/| because
* what was a union or intersection of type variables might be a simpler type
* after the type variables are instantiated. Finally, it
* maps poly params in the current constraint set back to their type vars.
*
* - re-evaluates all occurrences of And/OrType with &/| because
* what was a union or intersection of type variables might be a simpler type
* after the type variables are instantiated.
* - maps poly params in the current constraint set back to their type vars.
* - forces match types to be fully defined and tries to normalize them.
*
* NOTE: Simplifying an intersection type might change its erasure (for
* example, the Java erasure of `Object & Serializable` is `Object`,
Expand Down
3 changes: 2 additions & 1 deletion compiler/test-resources/repl/i5218
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ val tuple: (Int, String, Long) = (1,2,3)
scala> 0.0 *: tuple
val res0: (Double, Int, String, Long) = (0.0,1,2,3)
scala> tuple ++ tuple
val res1: Int *: scala.Tuple.Concat[(String, Long), tuple.type] = (1,2,3,1,2,3)
val res1: Int *: String *: Long *:
scala.Tuple.Concat[scala.Tuple$package.EmptyTuple.type, tuple.type] = (1,2,3,1,2,3)
7 changes: 7 additions & 0 deletions tests/pos/i11977.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test:

def add0(a : (Int, String), b : (Int, String)): Int =
val x = 3
x + b(0)

def add(a : (Int, String), b : (Int, String)) : (Int, String) = (a(0) + b(0), a(1) + b(1))