Skip to content

Commit 9b13653

Browse files
committed
Disallow by-name erased parameters
1 parent 78d2d67 commit 9b13653

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import MegaPhase.*
1515
import Decorators.*
1616
import typer.RefChecks
1717
import reporting.trace
18+
import dotty.tools.dotc.core.Names.Name
1819

1920
/** This phase implements the following transformations:
2021
*
@@ -79,11 +80,14 @@ class ElimByName extends MiniPhase, InfoTransformer:
7980
case ExprType(rt) if exprBecomesFunction(sym) =>
8081
defn.ByNameFunction(rt)
8182
case tp: MethodType =>
82-
def exprToFun(tp: Type) = tp match
83-
case ExprType(rt) => defn.ByNameFunction(rt)
83+
def exprToFun(tp: Type, name: Name) = tp match
84+
case ExprType(rt) =>
85+
if rt.hasAnnotation(defn.ErasedParamAnnot) then
86+
report.error(em"By-name parameter cannot be erased: $name", sym.srcPos)
87+
defn.ByNameFunction(rt)
8488
case tp => tp
8589
tp.derivedLambdaType(
86-
paramInfos = tp.paramInfos.mapConserve(exprToFun),
90+
paramInfos = tp.paramInfos.zipWithConserve(tp.paramNames)(exprToFun),
8791
resType = transformInfo(tp.resType, sym))
8892
case tp: PolyType =>
8993
tp.derivedLambdaType(resType = transformInfo(tp.resType, sym))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def f(x: => Int, erased y: => Int) = x // error
2+
def g(erased x: => Int, y: => Int) = y // error
3+
4+
val h: (erased => Int, Int) => Int = (erased x, y) => y // error

0 commit comments

Comments
 (0)