Skip to content

Commit 0afa50d

Browse files
authored
Fix "Regression in zio/zio-schema for typer/implicit resolution" (#24156)
Fixes implicit divergence checking regression by correcting how `TypeSizeAccumulator` handles `TypeParamRef` bounds. Instead of adding both upper and lower bounds to the type size, we now take the maximum of both bound sizes. Fixes #24007
1 parent eb67a9c commit 0afa50d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7066,7 +7066,10 @@ object Types extends TypeUtils {
70667066
case tp: TypeRef if tp.info.isTypeAlias =>
70677067
apply(n, tp.superType)
70687068
case tp: TypeParamRef =>
7069-
apply(n, TypeComparer.bounds(tp))
7069+
val bounds = TypeComparer.bounds(tp)
7070+
val loSize = apply(n, bounds.lo)
7071+
val hiSize = apply(n, bounds.hi)
7072+
hiSize max loSize
70707073
case tp: LazyRef =>
70717074
if seen.contains(tp) then n
70727075
else

tests/pos/i24007.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
sealed trait CaseSet:
2+
type EnumType
3+
4+
object CaseSet {
5+
def caseOf[A, Z >: A]: Cons[A, Empty[Z], Z] = ???
6+
type Aux[EnumType0] = CaseSet { type EnumType = EnumType0 }
7+
8+
final class Empty[Z] extends CaseSet:
9+
type EnumType = Z
10+
11+
final class Cons[A, +T <: CaseSet.Aux[Z], Z](head: A, tail: T) extends CaseSet:
12+
type EnumType = Z
13+
def ++[That](that: That)(implicit append: Append[Z, Cons[A, T, Z], That]): append.Out = ???
14+
}
15+
16+
sealed trait Append[EnumType, -Left, -Right]:
17+
type Out <: CaseSet.Aux[EnumType]
18+
19+
object Append:
20+
type WithOut[EnumType, Left, Right, Out0] = Append[EnumType, Left, Right] { type Out = Out0 }
21+
22+
implicit def AppendCons[A, Z, T <: CaseSet.Aux[Z], That <: CaseSet.Aux[Z]](implicit
23+
append: Append[Z, T, That]
24+
): Append.WithOut[Z, CaseSet.Cons[A, T, Z], That, CaseSet.Cons[A, append.Out, Z]] = ???
25+
26+
implicit def AppendEmptyLeft[T <: CaseSet.Aux[Z], Z]: Append.WithOut[Z, CaseSet.Empty[Z], T, T] =
27+
???
28+
29+
object Test:
30+
type UnionValue = Int | Boolean | String
31+
val _ = CaseSet.caseOf[Int, UnionValue] ++
32+
CaseSet.caseOf[Boolean, UnionValue] ++
33+
CaseSet.caseOf[String, UnionValue]

0 commit comments

Comments
 (0)