Skip to content

Commit 446f1c3

Browse files
committed
Use the index in the repl state for the line module
1 parent c606153 commit 446f1c3

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

compiler/src/dotty/tools/repl/ParseResult.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ object ParseResult {
115115
stats
116116
}
117117

118-
private[this] var replSessionNumber = 0
119-
120118
/** Extract a `ParseResult` from the string `sourceCode` */
121-
def apply(sourceCode: String)(implicit ctx: Context): ParseResult =
119+
def apply(sourceCode: String)(implicit state: State): ParseResult =
122120
sourceCode match {
123121
case "" => Newline
124122
case CommandExtract(cmd, arg) => cmd match {
@@ -132,11 +130,12 @@ object ParseResult {
132130
case _ => UnknownCommand(cmd)
133131
}
134132
case _ =>
135-
replSessionNumber += 1
136-
val source = SourceFile.virtual(str.REPL_SESSION_LINE + replSessionNumber, sourceCode)
133+
implicit val ctx: Context = state.context
134+
135+
val source = SourceFile.virtual(str.REPL_SESSION_LINE + (state.objectIndex + 1), sourceCode)
137136

138137
val reporter = newStoreReporter
139-
val stats = parseStats(sourceCode)(ctx.fresh.setReporter(reporter).withSource(source))
138+
val stats = parseStats(sourceCode)(state.context.fresh.setReporter(reporter).withSource(source))
140139

141140
if (reporter.hasErrors)
142141
SyntaxErrors(

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class ReplCompiler extends Compiler {
140140
private def createUnit(defs: Definitions)(implicit ctx: Context): CompilationUnit = {
141141
val objectName = ctx.source.file.toString
142142
assert(objectName.startsWith(str.REPL_SESSION_LINE))
143+
assert(objectName.endsWith(defs.state.objectIndex.toString))
143144
val objectTermName = ctx.source.file.toString.toTermName
144145
objectNames.update(defs.state.objectIndex, objectTermName)
145146

@@ -236,7 +237,7 @@ class ReplCompiler extends Compiler {
236237
PackageDef(Ident(nme.EMPTY_PACKAGE), List(wrapper))
237238
}
238239

239-
ParseResult(expr) match {
240+
ParseResult(expr)(state) match {
240241
case Parsed(_, trees) =>
241242
wrap(trees).result
242243
case SyntaxErrors(_, reported, trees) =>

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ReplDriver(settings: Array[String],
113113
implicit val ctx = state.context
114114
try {
115115
val line = terminal.readLine(completer)
116-
ParseResult(line)
116+
ParseResult(line)(state)
117117
} catch {
118118
case _: EndOfFileException |
119119
_: UserInterruptException => // Ctrl+D or Ctrl+C
@@ -132,7 +132,7 @@ class ReplDriver(settings: Array[String],
132132
}
133133

134134
final def run(input: String)(implicit state: State): State = withRedirectedOutput {
135-
val parsed = ParseResult(input)(state.context)
135+
val parsed = ParseResult(input)(state)
136136
interpret(parsed)
137137
}
138138

0 commit comments

Comments
 (0)