Skip to content

Commit 9d23aee

Browse files
authored
Merge pull request #87 from scala/backport-lts-3.3-21824
Backport "Avoid orphan param from default arg" to 3.3 LTS
2 parents c684200 + 2fad21f commit 9d23aee

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

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

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

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

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)