Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid orphan param from default arg #21824

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,11 @@ class Namer { typer: Typer =>
val pt = inherited.orElse(expectedDefaultArgType).orElse(fallbackProto).widenExpr
val tp = typedAheadRhs(pt).tpe
if (defaultTp eq pt) && (tp frozen_<:< defaultTp) then
// See i21558, the default argument new A(1.0) is of type A[?T]
// With an uninterpolated, invariant ?T type variable.
// So before we return the default getter parameter type (A[? <: Double])
// we want to force ?T to instantiate, so it's poly is removed from the constraint
isFullyDefined(tp, ForceDegree.all)
// When possible, widen to the default getter parameter type to permit a
// larger choice of overrides (see `default-getter.scala`).
// For justification on the use of `@uncheckedVariance`, see
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i21558.orig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Base
class A[T <: Float](val f: T) extends Base

def test() = {
m1(new A(m2()));

}

def m1(x: Base) = {}
def m2(p: A[? <: Float] = new A(1.0f)): Int = 1
8 changes: 8 additions & 0 deletions tests/pos/i21558.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Base
class A[T <: Double](val f: T) extends Base

class Test:
def test() = m1(new A(m2()))

def m1(x: Base): Unit = {}
def m2(p: A[? <: Double] = new A(1.0)): Int = 2
Loading