Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7124,7 +7124,15 @@ object Types extends TypeUtils {
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
var seen = util.HashSet[Type](initialCapacity = 8)
def apply(n: Int, tp: Type): Int =
tp match {

val canonicTp = tp match
case AppliedType(_, args) if defn.isTupleNType(tp) =>
args.foldRight(defn.EmptyTupleClass.typeRef: Type) { (elemType, acc) =>
defn.PairClass.typeRef.appliedTo(elemType, acc)
}
case _ => tp

canonicTp match {
case tp: AppliedType =>
val tpNorm = tp.tryNormalize
if tpNorm.exists then apply(n, tpNorm)
Expand Down
18 changes: 18 additions & 0 deletions compiler/test/dotty/tools/dotc/core/TypesTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dotty.tools.dotc.core

import dotty.tools.DottyTest
import dotty.tools.dotc.core.Symbols.defn
import dotty.tools.dotc.core.TypeOps

import org.junit.Test
import org.junit.Assert.assertEquals

class TypesTest extends DottyTest:

@Test def tuple3TypeSize =
val tpe = defn.TupleType(3).nn.appliedTo(List(defn.IntType, defn.BooleanType, defn.DoubleType))
assertEquals(3, tpe.typeSize)

@Test def tuple3ConsTypeSize =
val tpe = TypeOps.nestedPairs(List(defn.IntType, defn.BooleanType, defn.DoubleType))
assertEquals(3, tpe.typeSize)
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/dotc/typer/DivergenceChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class DivergenceCheckerTests extends DottyTest {
1,
1,
1,
3,
5
4,
6
)

tpes.lazyZip(expectedSizes).lazyZip(expectedCoveringSets).foreach {
Expand Down
Loading