Skip to content

Commit 43efeed

Browse files
committed
Only check for realizability for erased parameters of result-dependent functions
Per talk with @odersky, it seems that it is enough to check for realizability of parameters of a dependent function in order to avoid unsoundness. Note that the following actions have already been checked for, with erased parameters: - Using them as a dependent path in casting / variable definitions - Using them as the input to an `inline match` The check previously performed on `val`/`def` definitions are also removed, so we are as liberal as possible, to avoid too much restriction. I think with this, we can also remove the special case for `compiletime.erasedValue`.
1 parent f65ee63 commit 43efeed

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
301301
checkNoConstructorProxy(tree)
302302
transformSelect(tree, Nil)
303303
case tree: Apply =>
304-
val methType = tree.fun.tpe.widen
304+
val methType = tree.fun.tpe.widen.asInstanceOf[MethodType]
305305
val app =
306306
if (methType.isErasedMethod)
307307
tpd.cpy.Apply(tree)(
308308
tree.fun,
309309
tree.args.mapConserve(arg =>
310-
Checking.checkRealizable(arg.tpe, arg.srcPos, "erased argument")
310+
if methType.isResultDependent then
311+
Checking.checkRealizable(arg.tpe, arg.srcPos, "erased argument")
311312
if (methType.isImplicitMethod && arg.span.isSynthetic)
312313
arg match
313314
case _: RefTree | _: Apply | _: TypeApply if arg.symbol.is(Erased) =>
@@ -350,7 +351,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
350351
if (fn.symbol != defn.ChildAnnot.primaryConstructor)
351352
// Make an exception for ChildAnnot, which should really have AnyKind bounds
352353
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
353-
354354
fn match {
355355
case sel: Select =>
356356
val args1 = transform(args)
@@ -484,9 +484,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
484484
private def checkErasedDef(tree: ValOrDefDef)(using Context): Unit =
485485
if tree.symbol.is(Erased, butNot = Macro) then
486486
val tpe = tree.rhs.tpe
487-
if !tree.symbol.isOneOf(TermParamOrAccessor) && !tree.symbol.eq(defn.Compiletime_erasedValue) then // Only need to check non-parameters, since parameters have their own path checks.
488-
// We want all erased definitions to have a realizable type
489-
Checking.checkRealizable(tree.tpt.tpe, tree.srcPos, "erased type")
490487
if tpe.derivesFrom(defn.NothingClass) then
491488
report.error("`erased` definition cannot be implemented with en expression of type Nothing", tree.srcPos)
492489
else if tpe.derivesFrom(defn.NullClass) then

0 commit comments

Comments
 (0)