@@ -103,7 +103,7 @@ class ReplCompiler extends Compiler {
103103 Definitions (
104104 defs.toList,
105105 state.copy(
106- objectIndex = state.objectIndex + ( if (defs.isEmpty) 0 else 1 ) ,
106+ objectIndex = state.objectIndex + 1 ,
107107 valIndex = valIdx
108108 )
109109 )
@@ -123,29 +123,27 @@ class ReplCompiler extends Compiler {
123123 * }
124124 * ```
125125 */
126- private def wrapped (defs : Definitions , objectTermName : TermName ): untpd.PackageDef = {
126+ private def wrapped (defs : Definitions , objectTermName : TermName , span : Span ): untpd.PackageDef = {
127127 import untpd ._
128128
129- assert(defs.stats.nonEmpty)
130-
131129 implicit val ctx : Context = defs.state.context
132130
133131 val tmpl = Template (emptyConstructor, Nil , Nil , EmptyValDef , defs.stats)
134132 val module = ModuleDef (objectTermName, tmpl)
135- .withSpan(Span ( 0 , defs.stats.last. span.end) )
133+ .withSpan(span)
136134
137135 PackageDef (Ident (nme.EMPTY_PACKAGE ), List (module))
138136 }
139137
140- private def createUnit (defs : Definitions )(implicit ctx : Context ): CompilationUnit = {
138+ private def createUnit (defs : Definitions , span : Span )(implicit ctx : Context ): CompilationUnit = {
141139 val objectName = ctx.source.file.toString
142140 assert(objectName.startsWith(str.REPL_SESSION_LINE ))
143141 assert(objectName.endsWith(defs.state.objectIndex.toString))
144142 val objectTermName = ctx.source.file.toString.toTermName
145143 objectNames.update(defs.state.objectIndex, objectTermName)
146144
147145 val unit = CompilationUnit (ctx.source)
148- unit.untpdTree = wrapped(defs, objectTermName)
146+ unit.untpdTree = wrapped(defs, objectTermName, span )
149147 unit
150148 }
151149
@@ -158,8 +156,9 @@ class ReplCompiler extends Compiler {
158156 }
159157
160158 final def compile (parsed : Parsed )(implicit state : State ): Result [(CompilationUnit , State )] = {
159+ assert(! parsed.trees.isEmpty)
161160 val defs = definitions(parsed.trees, state)
162- val unit = createUnit(defs)(state.context)
161+ val unit = createUnit(defs, Span ( 0 , parsed.trees.last.span.end) )(state.context)
163162 runCompilationUnit(unit, defs.state)
164163 }
165164
0 commit comments