Skip to content

Commit fb48239

Browse files
authored
Avoid orphan param from default arg (#21824)
2 parents b712447 + e8136b7 commit fb48239

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Namer.scala

+5
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,11 @@ class Namer { typer: Typer =>
21302130
val pt = inherited.orElse(expectedDefaultArgType).orElse(fallbackProto).widenExpr
21312131
val tp = typedAheadRhs(pt).tpe
21322132
if (defaultTp eq pt) && (tp frozen_<:< defaultTp) then
2133+
// See i21558, the default argument new A(1.0) is of type A[?T]
2134+
// With an uninterpolated, invariant ?T type variable.
2135+
// So before we return the default getter parameter type (A[? <: Double])
2136+
// we want to force ?T to instantiate, so it's poly is removed from the constraint
2137+
isFullyDefined(tp, ForceDegree.all)
21332138
// When possible, widen to the default getter parameter type to permit a
21342139
// larger choice of overrides (see `default-getter.scala`).
21352140
// For justification on the use of `@uncheckedVariance`, see

Diff for: tests/pos/i21558.orig.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Base
2+
class A[T <: Float](val f: T) extends Base
3+
4+
def test() = {
5+
m1(new A(m2()));
6+
7+
}
8+
9+
def m1(x: Base) = {}
10+
def m2(p: A[? <: Float] = new A(1.0f)): Int = 1

Diff for: tests/pos/i21558.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Base
2+
class A[T <: Double](val f: T) extends Base
3+
4+
class Test:
5+
def test() = m1(new A(m2()))
6+
7+
def m1(x: Base): Unit = {}
8+
def m2(p: A[? <: Double] = new A(1.0)): Int = 2

0 commit comments

Comments
 (0)