Skip to content

Commit b4a1c5b

Browse files
committed
Add missing spans in closures
Previously they where infered from the mods.
1 parent 23d51d3 commit b4a1c5b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,14 @@ object desugar {
933933
* def $anonfun(params) = body
934934
* Closure($anonfun)
935935
*/
936-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = null, isImplicit: Boolean)(implicit ctx: Context): Block =
936+
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = null, isImplicit: Boolean)(implicit ctx: Context): Block = {
937+
val span = params.headOption.fold(body.span)(_.span.union(body.span))
937938
Block(
938939
DefDef(nme.ANON_FUN, Nil, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
940+
.withSpan(span)
939941
.withMods(synthetic | Artifact),
940-
Closure(Nil, Ident(nme.ANON_FUN), if (isImplicit) ImplicitEmptyTree else EmptyTree))
942+
Closure(Nil, Ident(nme.ANON_FUN), if (isImplicit) ImplicitEmptyTree else EmptyTree)).withSpan(span)
943+
}
941944

942945
/** If `nparams` == 1, expand partial function
943946
*

compiler/test/dotty/tools/repl/TabcompleteTests.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TabcompleteTests extends ReplTest {
3636

3737
fromInitialState { implicit state =>
3838
val comp = tabComplete(src1)
39-
assertEquals(List(), comp.sorted) // FIXME? or is this intended?
39+
assertEquals(List("map", "mapConserve"), comp.sorted)
4040
state
4141
}
4242
.andThen { implicit state =>
@@ -90,4 +90,10 @@ class TabcompleteTests extends ReplTest {
9090
val expected = List("Renamed")
9191
assertEquals(expected, tabComplete("val foo: Rena"))
9292
}
93+
94+
@Test def tabClosureComplete = fromInitialState { implicit s =>
95+
assertEquals(List("map", "mapConserve"), tabComplete("Nil.map"))
96+
assertEquals(List("map", "mapConserve"), tabComplete("(x: Int => Int) => Nil.map"))
97+
assertEquals(List("apply"), tabComplete("(x: Int => Int) => x.ap"))
98+
}
9399
}

0 commit comments

Comments
 (0)