From 6eaf2c905600d7a0b6c163c8df32931868b39f00 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 17 Aug 2023 23:56:57 +0100 Subject: [PATCH] Fix failing bounds check on default getter The type arguments on the default argument had the wrong span, which means that they were getting bounds checked. This is in contrast the other other type arguments (the ones on check itself), which aren't bounds checked - by not passing the isZeroExtent guard in checkInferredWellFormed. [Cherry-picked e8c8038548d90a54eb2d2a3bfe4a13700d70dcce] --- .../src/dotty/tools/dotc/typer/Applications.scala | 2 +- tests/pos/i18253.orig.scala | 15 +++++++++++++++ tests/pos/i18253.scala | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i18253.orig.scala create mode 100644 tests/pos/i18253.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index eebb63590961..19af6b02c25d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -333,7 +333,7 @@ object Applications { // it's crucial that the type tree is not copied directly as argument to // `cpy$default$1`. If it was, the variable `X'` would already be interpolated // when typing the default argument, which is too early. - spliceMeth(meth, fn).appliedToTypes(targs.tpes) + spliceMeth(meth, fn).appliedToTypeTrees(targs.map(targ => TypeTree(targ.tpe).withSpan(targ.span))) case _ => meth } diff --git a/tests/pos/i18253.orig.scala b/tests/pos/i18253.orig.scala new file mode 100644 index 000000000000..9efe1224ebfd --- /dev/null +++ b/tests/pos/i18253.orig.scala @@ -0,0 +1,15 @@ +import compiletime.ops.int.Max + +trait DFSInt[W <: Int] +trait Candidate[R]: + type OutW <: Int +object Candidate: + given [W <: Int, R <: DFSInt[W]]: Candidate[R] with + type OutW = W + +def foo[R](rhs: R)(using icR: Candidate[R]): DFSInt[Max[8, icR.OutW]] = ??? + +object Test: + def check[A](a: A, clue: Int = 1): Unit = ??? + val x: DFSInt[8] = ??? + check(foo(x)) diff --git a/tests/pos/i18253.scala b/tests/pos/i18253.scala new file mode 100644 index 000000000000..8f395ee8e943 --- /dev/null +++ b/tests/pos/i18253.scala @@ -0,0 +1,14 @@ +import scala.compiletime.ops.int.Max + +trait Foo[A] +trait Bar[B]: + type Out <: Int +object Bar: + given inst[C <: Int]: Bar[C] with + type Out = C + +class Test: + def mkFoo(using bx: Bar[2]): Foo[Max[1, bx.Out]] = ??? + def check[Y](yy: Y, clue: Int = 1): Unit = () + + def test: Unit = check(mkFoo)