Skip to content

Commit 9b6184b

Browse files
author
EnzeXing
committed
Fix i18628
1 parent d652c3e commit 9b6184b

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
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
@@ -589,7 +589,7 @@ object Objects:
589589
values.map(ref => ref.widen(height)).join
590590

591591
case Fun(code, thisV, klass, env) =>
592-
Fun(code, thisV.widenRefOrCold(height), klass, env.widen(height))
592+
Fun(code, thisV.widenRefOrCold(height), klass, env.widen(height - 1))
593593

594594
case ref @ OfClass(klass, outer, _, args, env) =>
595595
val outer2 = outer.widen(height - 1)

tests/init-global/pos/i18628.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test:
2+
class Box(val x: Int)
3+
4+
def recur(a: => Box, b: => Box): Int =
5+
a.x + recur(a, b) + b.x
6+
7+
recur(Box(1), Box(2))

tests/init-global/pos/i18628_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test:
2+
class Box(val x: Int)
3+
4+
def recur(a: => Box, b: Box): Int =
5+
a.x + recur(a, b) + b.x
6+
7+
recur(Box(1), Box(2))

tests/init-global/pos/i18628_3.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.annotation.init.widen
2+
3+
object Test:
4+
class Box(val x: Int)
5+
6+
def recur(a: => Box, b: => Box): Int =
7+
a.x + recur(a: @widen(5), b: @widen(5)) + b.x
8+
9+
recur(Box(1), Box(2))

0 commit comments

Comments
 (0)