-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't follow BaseType of abstract binders in MT reduction
Fix #11982 and the associated soundness problem. The issue with the behavior on master arises from the fact that type binder of match types might change as context gets more precise, which results in a single match type reducing in two different ways. This issue comes from the fact that subtyping looks into base types, and is thus able to match a type such as `T <: Tuple2[Int, Int]` against a pattern `case Tuple2[a, b]`, even if the best solutions for `a` and `b` in the current context are not guaranteed to be the best solution in more precise contexts (such as at call site in the added test case).
- Loading branch information
1 parent
ee6733a
commit d1957e5
Showing
10 changed files
with
104 additions
and
9 deletions.
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
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,40 @@ | ||
// testCompilation 11982.scala | ||
type Head[X] = X match { | ||
case Tuple2[a, b] => a | ||
} | ||
|
||
object Unpair { | ||
def unpair[X <: Tuple2[Any, Any]]: Head[X] = 1 // error | ||
unpair[Tuple2["msg", 42]]: "msg" | ||
} | ||
|
||
|
||
type Head2[X] = X match { | ||
case Tuple2[Tuple2[a, b], Tuple2[c, d]] => a | ||
} | ||
|
||
object Unpair2 { | ||
def unpair[X <: Tuple2[Tuple2[Any, Any], Tuple2[Any, Any]]]: Head2[X] = 1 // error | ||
unpair[Tuple2[Tuple2["msg", 42], Tuple2[41, 40]]]: "msg" | ||
} | ||
|
||
|
||
type Head3[X] = X match { | ||
case Tuple2[a, b] => a | ||
} | ||
|
||
object Unpair3 { | ||
def unpair[X <: Tuple2[Any, Any]]: Head3[Tuple2[X, X]] = (1, 2) // error | ||
unpair[Tuple2["msg", 42]]: ("msg", 42) | ||
} | ||
|
||
trait Foo[+A, +B] | ||
|
||
type Head4[X] = X match { | ||
case Foo[Foo[a, b], Foo[c, d]] => a | ||
} | ||
|
||
object Unpair4 { | ||
def unpair[X <: Foo[Any, Any]]: Head4[Foo[X, X]] = 1 // error | ||
unpair[Foo["msg", 42]]: "msg" | ||
} |
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
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,9 @@ | ||
object Unpair { | ||
class Inv[T] | ||
|
||
type Head[X] = X match { | ||
case Tuple2[a, b] => a | ||
} | ||
|
||
def unpair[X <: Tuple2[Any, Any]]: Head[X] = ??? | ||
} |
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,5 @@ | ||
object UnpairApp { | ||
import Unpair._ | ||
|
||
val x: String = unpair[("msg", 42)] | ||
} |
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