Skip to content

Commit b433244

Browse files
committed
add support for precise default arguments
1 parent 190cd31 commit b433244

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,19 +1855,18 @@ class Namer { typer: Typer =>
18551855
case _ =>
18561856
approxTp
18571857

1858-
var rhsCtx = ctx.fresh.addMode(Mode.InferringReturnType)
1859-
if sym.isInlineMethod then rhsCtx = rhsCtx.addMode(Mode.InlineableBody)
1860-
if sym.is(ExtensionMethod) then rhsCtx = rhsCtx.addMode(Mode.InExtensionMethod)
1861-
val typeParams = paramss.collect { case TypeSymbols(tparams) => tparams }.flatten
1862-
if (typeParams.nonEmpty) {
1863-
// we'll be typing an expression from a polymorphic definition's body,
1864-
// so we must allow constraining its type parameters
1865-
// compare with typedDefDef, see tests/pos/gadt-inference.scala
1866-
rhsCtx.setFreshGADTBounds
1867-
rhsCtx.gadt.addToConstraint(typeParams)
1868-
}
1869-
1870-
def typedAheadRhs(pt: Type) =
1858+
def typedAheadRhs(pt: Type)(using Context) =
1859+
var rhsCtx = ctx.fresh.addMode(Mode.InferringReturnType)
1860+
if sym.isInlineMethod then rhsCtx = rhsCtx.addMode(Mode.InlineableBody)
1861+
if sym.is(ExtensionMethod) then rhsCtx = rhsCtx.addMode(Mode.InExtensionMethod)
1862+
val typeParams = paramss.collect { case TypeSymbols(tparams) => tparams }.flatten
1863+
if (typeParams.nonEmpty) {
1864+
// we'll be typing an expression from a polymorphic definition's body,
1865+
// so we must allow constraining its type parameters
1866+
// compare with typedDefDef, see tests/pos/gadt-inference.scala
1867+
rhsCtx.setFreshGADTBounds
1868+
rhsCtx.gadt.addToConstraint(typeParams)
1869+
}
18711870
PrepareInlineable.dropInlineIfError(sym,
18721871
typedAheadExpr(mdef.rhs, pt)(using rhsCtx))
18731872

@@ -1877,7 +1876,8 @@ class Namer { typer: Typer =>
18771876
// parameters like in `def mkList[T](value: T = 1): List[T]`.
18781877
val defaultTp = defaultParamType
18791878
val pt = inherited.orElse(expectedDefaultArgType).orElse(fallbackProto).widenExpr
1880-
val tp = typedAheadRhs(pt).tpe
1879+
val preciseMode = if (defaultTp.isPrecise) Mode.Precise else Mode.None
1880+
val tp = withMode(preciseMode){ typedAheadRhs(pt) }.tpe
18811881
if (defaultTp eq pt) && (tp frozen_<:< defaultTp) then
18821882
// When possible, widen to the default getter parameter type to permit a
18831883
// larger choice of overrides (see `default-getter.scala`).

0 commit comments

Comments
 (0)