Skip to content

Commit b93523d

Browse files
committed
Fix Closure span assignment in makeClosure
1 parent e560c2d commit b93523d

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
@@ -1412,7 +1412,9 @@ object desugar {
14121412
DefDef(nme.ANON_FUN, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
14131413
.withSpan(span)
14141414
.withMods(synthetic | Artifact),
1415-
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree))
1415+
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree)
1416+
.withSpan(span)
1417+
)
14161418

14171419
/** If `nparams` == 1, expand partial function
14181420
*

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

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

16891749
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)