Skip to content

Commit 11d7fa3

Browse files
committed
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 #10929
1 parent 4d62692 commit 11d7fa3

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23012301
}
23022302

23032303
def typedRefinedTypeTree(tree: untpd.RefinedTypeTree)(using Context): TypTree = {
2304-
val tpt1 = if (tree.tpt.isEmpty) TypeTree(defn.ObjectType) else typedAheadType(tree.tpt)
2304+
val tpt1 = if tree.tpt == EmptyTree then TypeTree(defn.ObjectType) else typedAheadType(tree.tpt)
23052305
val refineClsDef = desugar.refinedTypeToClass(tpt1, tree.refinements).withSpan(tree.span)
23062306
val refineCls = createSymbol(refineClsDef).asClass
23072307
val TypeDef(_, impl: Template) = typed(refineClsDef): @unchecked

tests/pos/hylolib-deferred-given/Hasher.scala

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//> using options -language:experimental.modularity -source future
12
package hylo
23

34
import scala.util.Random

tests/pos/i10929.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//> using options -language:experimental.modularity -source future
2+
infix abstract class TupleOf[T, +A]:
3+
type Mapped[+A] <: Tuple
4+
def map[B](x: T)(f: A => B): Mapped[B]
5+
6+
object TupleOf:
7+
8+
given TupleOf[EmptyTuple, Nothing] with
9+
type Mapped[+A] = EmptyTuple
10+
def map[B](x: EmptyTuple)(f: Nothing => B): Mapped[B] = x
11+
12+
given [A, Rest <: Tuple](using tracked val tup: Rest TupleOf A): TupleOf[A *: Rest, A] with
13+
type Mapped[+A] = A *: tup.Mapped[A]
14+
def map[B](x: A *: Rest)(f: A => B): Mapped[B] =
15+
(f(x.head) *: tup.map(x.tail)(f))
16+
17+
def foo[T](xs: T)(using tup: T TupleOf Int): tup.Mapped[Int] = tup.map(xs)(_ + 1)
18+
19+
@main def test =
20+
foo(EmptyTuple): EmptyTuple // ok
21+
foo(1 *: EmptyTuple): Int *: EmptyTuple // now also ok

tests/pos/i13580.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -language:experimental.modularity -source future
2+
trait IntWidth:
3+
type Out
4+
given IntWidth:
5+
type Out = 155
6+
7+
trait IntCandidate:
8+
type Out
9+
given (using tracked val w: IntWidth) => IntCandidate:
10+
type Out = w.Out
11+
12+
val x = summon[IntCandidate]
13+
val xx = summon[x.Out =:= 155]

0 commit comments

Comments
 (0)