Skip to content

Commit d3d38e4

Browse files
committed
Check realizability of parameters of an erased function
... instead of checking every instantiated instance of erasedValue[T]. I think this is the better solution, since erasedValue have uses outside of erasedDefinitions (i.e. in inlining) which has their own realizability checks as well. We don't have to be pessimistic in those cases.
1 parent bd05ef4 commit d3d38e4

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
307307
tpd.cpy.Apply(tree)(
308308
tree.fun,
309309
tree.args.mapConserve(arg =>
310+
Checking.checkRealizable(arg.tpe, arg.srcPos, "erased argument")
310311
if (methType.isImplicitMethod && arg.span.isSynthetic)
311312
arg match
312313
case _: RefTree | _: Apply | _: TypeApply if arg.symbol.is(Erased) =>
@@ -349,10 +350,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
349350
if (fn.symbol != defn.ChildAnnot.primaryConstructor)
350351
// Make an exception for ChildAnnot, which should really have AnyKind bounds
351352
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
352-
if fn.symbol eq defn.Compiletime_erasedValue then
353-
// Check the instantiated type of erasedValue for realizibility
354-
for arg <- args do
355-
Checking.checkRealizable(arg.tpe, arg.srcPos, "type application of erasedValue")
356353

357354
fn match {
358355
case sel: Select =>

tests/neg-custom-args/erased/i4060.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object App {
77
def upcast(erased a: A)(x: Any): a.L = x
88
//lazy val p: A { type L <: Nothing } = p
99
erased val p: A { type L <: Nothing } = p // error
10-
def coerce(x: Any): Int = upcast(p)(x)
10+
def coerce(x: Any): Int = upcast(p)(x) // error
1111

1212
def coerceInline(x: Any): Int = upcast(compiletime.erasedValue[A {type L <: Nothing}])(x) // error
1313

0 commit comments

Comments
 (0)