Skip to content

Commit 3212890

Browse files
authored
Fix failing bounds check on default getter (#18419)
The type arguments on the default argument had the wrong span, which means that they were getting bounds checked. This is in contrast to the other type arguments (the ones on check itself), which aren't bounds checked - by not passing the isZeroExtent guard in checkInferredWellFormed.
2 parents 41d45a7 + e8c8038 commit 3212890

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ object Applications {
333333
// it's crucial that the type tree is not copied directly as argument to
334334
// `cpy$default$1`. If it was, the variable `X'` would already be interpolated
335335
// when typing the default argument, which is too early.
336-
spliceMeth(meth, fn).appliedToTypes(targs.tpes)
336+
spliceMeth(meth, fn).appliedToTypeTrees(targs.map(targ => TypeTree(targ.tpe).withSpan(targ.span)))
337337
case _ => meth
338338
}
339339

tests/pos/i18253.orig.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import compiletime.ops.int.Max
2+
3+
trait DFSInt[W <: Int]
4+
trait Candidate[R]:
5+
type OutW <: Int
6+
object Candidate:
7+
given [W <: Int, R <: DFSInt[W]]: Candidate[R] with
8+
type OutW = W
9+
10+
def foo[R](rhs: R)(using icR: Candidate[R]): DFSInt[Max[8, icR.OutW]] = ???
11+
12+
object Test:
13+
def check[A](a: A, clue: Int = 1): Unit = ???
14+
val x: DFSInt[8] = ???
15+
check(foo(x))

tests/pos/i18253.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.compiletime.ops.int.Max
2+
3+
trait Foo[A]
4+
trait Bar[B]:
5+
type Out <: Int
6+
object Bar:
7+
given inst[C <: Int]: Bar[C] with
8+
type Out = C
9+
10+
class Test:
11+
def mkFoo(using bx: Bar[2]): Foo[Max[1, bx.Out]] = ???
12+
def check[Y](yy: Y, clue: Int = 1): Unit = ()
13+
14+
def test: Unit = check(mkFoo)

0 commit comments

Comments
 (0)