Skip to content

Commit a382793

Browse files
committed
Fix Closure span assignment in makeClosure
1 parent 5a9b616 commit a382793

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,9 @@ object desugar {
14231423
DefDef(nme.ANON_FUN, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
14241424
.withSpan(span)
14251425
.withMods(synthetic | Artifact),
1426-
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree))
1426+
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree)
1427+
.withSpan(span)
1428+
)
14271429

14281430
/** If `nparams` == 1, expand partial function
14291431
*

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,66 @@ class DottyBytecodeTests extends DottyBytecodeTest {
16821682
assertSameCode(instructions, expected)
16831683
}
16841684
}
1685+
1686+
@Test def i15098 = {
1687+
val source =
1688+
"""object Main {
1689+
| def main(args: Array[String]): Unit = {
1690+
| Array(1).foreach { n =>
1691+
| val x = 123
1692+
| println(n)
1693+
| }
1694+
| }
1695+
|}
1696+
""".stripMargin
1697+
1698+
checkBCode(source) { dir =>
1699+
val clsIn = dir.lookupName("Main$.class", directory = false).input
1700+
val clsNode = loadClassNode(clsIn, skipDebugInfo = false)
1701+
val method = getMethod(clsNode, "main")
1702+
val instructions = instructionsFromMethod(method).filter(_.isInstanceOf[LineNumber])
1703+
1704+
val expected = List(
1705+
LineNumber(2, Label(0)),
1706+
LineNumber(3, Label(0)),
1707+
)
1708+
1709+
assertSameCode(instructions, expected)
1710+
}
1711+
}
1712+
1713+
@Test def i15098_2 = {
1714+
val source =
1715+
"""object Main {
1716+
| def main(args: Array[String]): Unit = {
1717+
| Array(1).map { n =>
1718+
| val x = 123
1719+
| x + n
1720+
| }.foreach { n =>
1721+
| println(n)
1722+
| println(n)
1723+
| }
1724+
| }
1725+
|}
1726+
""".stripMargin
1727+
1728+
checkBCode(source) { dir =>
1729+
val clsIn = dir.lookupName("Main$.class", directory = false).input
1730+
val clsNode = loadClassNode(clsIn, skipDebugInfo = false)
1731+
val method = getMethod(clsNode, "main")
1732+
val instructions = instructionsFromMethod(method).filter(_.isInstanceOf[LineNumber])
1733+
1734+
val expected = List(
1735+
LineNumber(2, Label(0)),
1736+
LineNumber(3, Label(0)),
1737+
LineNumber(6, Label(17)),
1738+
LineNumber(3, Label(26)),
1739+
LineNumber(6, Label(29)),
1740+
)
1741+
1742+
assertSameCode(instructions, expected)
1743+
}
1744+
}
16851745
}
16861746

16871747
object invocationReceiversTestCode {

tests/neg/i9299.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
type F <: F = 1 match { // error
2-
case _ => foo.foo // error // error
2+
case _ => foo.foo // error
33
}
44
def foo(a: Int): Unit = ???

0 commit comments

Comments
 (0)