From f5ba0e9b25b5cab678c4274bbb4c80a80d244c31 Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 18 Jan 2024 16:43:42 +0100 Subject: [PATCH] Use inferred type transformer for SeqLiterals Fixes #19470 --- compiler/src/dotty/tools/dotc/cc/Setup.scala | 2 +- tests/neg/i19470.check | 7 +++++++ tests/neg/i19470.scala | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i19470.check create mode 100644 tests/neg/i19470.scala diff --git a/compiler/src/dotty/tools/dotc/cc/Setup.scala b/compiler/src/dotty/tools/dotc/cc/Setup.scala index 18781e5ab713..44e832a20d34 100644 --- a/compiler/src/dotty/tools/dotc/cc/Setup.scala +++ b/compiler/src/dotty/tools/dotc/cc/Setup.scala @@ -416,7 +416,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI: case tree @ SeqLiteral(elems, tpt: TypeTree) => traverse(elems) - transformTT(tpt, boxed = true, exact = false) + tpt.rememberType(box(transformInferredType(tpt.tpe))) case _ => traverseChildren(tree) diff --git a/tests/neg/i19470.check b/tests/neg/i19470.check new file mode 100644 index 000000000000..72f811f7ea3b --- /dev/null +++ b/tests/neg/i19470.check @@ -0,0 +1,7 @@ +-- [E007] Type Mismatch Error: tests/neg/i19470.scala:9:12 ------------------------------------------------------------- +9 | List(foo(f())) // error + | ^^^^^^^^ + | Found: Inv[? >: IO <: box IO^{f}] + | Required: box Inv[box IO^?]^? + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i19470.scala b/tests/neg/i19470.scala new file mode 100644 index 000000000000..9659f4654042 --- /dev/null +++ b/tests/neg/i19470.scala @@ -0,0 +1,9 @@ +import language.experimental.captureChecking +trait IO +case class Inv[X](x: X) + +def foo(x: IO^): Inv[IO^{x}] = Inv(x) + +def main(io: IO^): Unit = + def test(f: () => IO^) = + List(foo(f())) // error