Skip to content

Commit de2801b

Browse files
author
EnzeXing
committed
Cache result during thunk evaluation
1 parent 5e63644 commit de2801b

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ class Objects(using Context @constructorOnly):
13601360
case env: Env.EnvRef => Env.ofByName(sym, thisV, Env.EnvSet(Set(env)))
13611361
}
13621362
given Scope = byNameEnv
1363-
eval(code, thisV, klass)
1363+
eval(code, thisV, klass, cacheResult = true)
13641364
case UnknownValue =>
13651365
reportWarningForUnknownValue("Calling on unknown value. " + Trace.show, Trace.position)
13661366
case Bottom => Bottom

tests/init-global/warn/i18628_2.scala renamed to tests/init-global/pos/i18628_2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ object Test:
22
class Box(val x: Int)
33

44
def recur(a: => Box, b: Box): Int =
5-
a.x + recur(a, b) + b.x // warn
5+
a.x + recur(a, b) + b.x
66

77
recur(Box(1), Box(2))

tests/init-global/warn/i18628_3.scala renamed to tests/init-global/pos/i18628_3.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object Test:
66
class Box(val x: Int)
77

88
def recur(a: => Box, b: => Box): Int =
9-
a.x + recur(a: @widen(5), b: @widen(5)) + b.x // warn // warn
9+
a.x + recur(a: @widen(5), b: @widen(5)) + b.x
1010

1111
recur(Box(1), Box(2))

tests/init-global/warn/i18628.scala renamed to tests/init-global/pos/i18628_4.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ object Test:
22
class Box(val x: Int)
33

44
def recur(a: => Box, b: => Box): Int =
5-
a.x + recur(a, b) + b.x // warn // warn
5+
a.x + recur(a, b) + b.x
66

77
recur(Box(1), Box(2))

0 commit comments

Comments
 (0)