Skip to content

Commit 667c17a

Browse files
committed
Fix semantics of by-name parameter
1 parent f9c0130 commit 667c17a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,12 @@ class Objects {
719719
// - look up parameters from environment
720720
// - evaluate the rhs of the local definition for val definitions: they are already cached
721721
val sym = tmref.symbol
722-
if sym.is(Flags.Param) then Result(env.getOrElse(sym, TypeAbs(sym.info)), Nil)
722+
if sym.is(Flags.Param) then
723+
val res = Result(env.getOrElse(sym, TypeAbs(sym.info)), Nil)
724+
if sym.info.isInstanceOf[ExprType] then
725+
res.call(defn.Function0_apply, Nil, superType = NoType, source)
726+
else
727+
res
723728
else if sym.is(Flags.Mutable) then Result(TypeAbs(sym.info), Nil)
724729
else if sym.is(Flags.Package) then Result(Bottom, Nil)
725730
else if sym.hasSource then

tests/init/crash/by-name.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def time[A](f: => A): A =
2+
val start = System.nanoTime
3+
val res = f
4+
val elapsed = (System.nanoTime - start)
5+
res
6+
7+
case class Foo(data: Int)
8+
9+
object o:
10+
val foo = time(Foo(3))
11+
println(foo.data)

0 commit comments

Comments
 (0)