forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Fix typing of RefinedTypes with watching parents
If a refined type has a parent type watching some other type, the parent should not be mapped to Object. Previously, the parent counted as `isEmpty` which caused this mapping. Fixes scala#10929
- Loading branch information
Showing
4 changed files
with
36 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//> using options -language:experimental.modularity -source future | ||
package hylo | ||
|
||
import scala.util.Random | ||
|
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,21 @@ | ||
//> using options -language:experimental.modularity -source future | ||
infix abstract class TupleOf[T, +A]: | ||
type Mapped[+A] <: Tuple | ||
def map[B](x: T)(f: A => B): Mapped[B] | ||
|
||
object TupleOf: | ||
|
||
given TupleOf[EmptyTuple, Nothing] with | ||
type Mapped[+A] = EmptyTuple | ||
def map[B](x: EmptyTuple)(f: Nothing => B): Mapped[B] = x | ||
|
||
given [A, Rest <: Tuple](using tracked val tup: Rest TupleOf A): TupleOf[A *: Rest, A] with | ||
type Mapped[+A] = A *: tup.Mapped[A] | ||
def map[B](x: A *: Rest)(f: A => B): Mapped[B] = | ||
(f(x.head) *: tup.map(x.tail)(f)) | ||
|
||
def foo[T](xs: T)(using tup: T TupleOf Int): tup.Mapped[Int] = tup.map(xs)(_ + 1) | ||
|
||
@main def test = | ||
foo(EmptyTuple): EmptyTuple // ok | ||
foo(1 *: EmptyTuple): Int *: EmptyTuple // now also ok |
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,13 @@ | ||
//> using options -language:experimental.modularity -source future | ||
trait IntWidth: | ||
type Out | ||
given IntWidth: | ||
type Out = 155 | ||
|
||
trait IntCandidate: | ||
type Out | ||
given (using tracked val w: IntWidth) => IntCandidate: | ||
type Out = w.Out | ||
|
||
val x = summon[IntCandidate] | ||
val xx = summon[x.Out =:= 155] |