-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix regression in instantiating type vars #16999
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
class Fn: | ||
class R[Y] | ||
|
||
case class Foo[F[_]](nest: Foo[F]): | ||
case class Bar[G[_], R[_]](value: Foo[G]) | ||
|
||
def bar[G[_]](using fn: Fn): Bar[G, fn.R] = ??? | ||
|
||
def part[G[_]](using fn: Fn): Bar[G, fn.R] = | ||
(bar[G], ()) match | ||
case (Bar(value), ()) => | ||
Bar(Foo(value)) |
This file contains hidden or 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,63 @@ | ||
class Funs { | ||
sealed trait ->[A, B] | ||
} | ||
|
||
/** | ||
* Binary tree with leafs holding values of types `F[X]`, `F[Y]`, ... | ||
* The complete structure of the tree is expressed by the type `A`, using the tags for branches and leafs. | ||
* | ||
* @tparam <*> tag for branches | ||
* @tparam T tag for leafs. | ||
* @tparam F value type of leafs. Each leaf holds a value of type `F[T]`, for some type `T`. | ||
* @tparam A captures the complete structure of the tree | ||
*/ | ||
enum Tree[<*>[_, _], T[_], F[_], A] { | ||
case Branch[<*>[_, _], T[_], F[_], A, B]( | ||
l: Tree[<*>, T, F, A], | ||
r: Tree[<*>, T, F, B], | ||
) extends Tree[<*>, T, F, A <*> B] | ||
|
||
case Leaf[<*>[_, _], T[_], F[_], A]( | ||
value: F[A], | ||
) extends Tree[<*>, T, F, T[A]] | ||
|
||
def <*>[B](that: Tree[<*>, T, F, B]): Tree[<*>, T, F, A <*> B] = | ||
Branch(this, that) | ||
|
||
def partition[G[_], H[_]]( | ||
f: [x] => F[x] => Either[G[x], H[x]], | ||
)(using | ||
funs: Funs, | ||
): Partitioned[G, H, funs.->] = | ||
this match { | ||
case Leaf(a) => | ||
f(a) match | ||
case Left(a) => Partitioned.Left(Leaf(a)) | ||
case Right(a) => Partitioned.Right(Leaf(a)) | ||
case Branch(l, r) => | ||
import Partitioned.{Both, Left, Right} | ||
import l.Partitioned.{Both => LBoth, Left => LLeft, Right => LRight} | ||
import r.Partitioned.{Both => RBoth, Left => RLeft, Right => RRight} | ||
|
||
(l.partition(f), r.partition(f)) match | ||
case (LLeft(lg), RLeft(rg)) => Left(lg <*> rg) | ||
case (LLeft(lg), RRight(rh)) => Both(lg, rh) | ||
case (LLeft(lg), RBoth(rg, rh)) => Both(lg <*> rg, rh) | ||
case (LRight(lh), RLeft(rg)) => Both(rg, lh) | ||
case (LRight(lh), RRight(rh)) => Right(lh <*> rh) | ||
case (LRight(lh), RBoth(rg, rh)) => Both(rg, lh <*> rh) | ||
case (LBoth(lg, lh), RLeft(rg)) => Both(lg <*> rg, lh) | ||
case (LBoth(lg, lh), RRight(rh)) => Both(lg, lh <*> rh) | ||
case (LBoth(lg, lh), RBoth(rg, rh)) => Both(lg <*> rg, lh <*> rh) | ||
} | ||
|
||
// note that `->` is never even used, to keep this reproduction case small | ||
enum Partitioned[G[_], H[_], ->[_, _]] { | ||
case Left(value: Tree[<*>, T, G, A]) | ||
case Right(value: Tree[<*>, T, H, A]) | ||
case Both[G[_], H[_], X, Y, ->[_, _]]( | ||
l: Tree[<*>, T, G, X], | ||
r: Tree[<*>, T, H, Y], | ||
) extends Partitioned[G, H, ->] | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird: Any is not kind-polymorphic, it's not supposed to be applicable to arguments. I've opened a PR which I believe fixes the root issue: #17025