File tree 3 files changed +9
-9
lines changed
compiler/src/dotty/tools/repl
3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -115,10 +115,8 @@ object ParseResult {
115
115
stats
116
116
}
117
117
118
- private [this ] var replSessionNumber = 0
119
-
120
118
/** 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 =
122
120
sourceCode match {
123
121
case " " => Newline
124
122
case CommandExtract (cmd, arg) => cmd match {
@@ -132,11 +130,12 @@ object ParseResult {
132
130
case _ => UnknownCommand (cmd)
133
131
}
134
132
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)
137
136
138
137
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))
140
139
141
140
if (reporter.hasErrors)
142
141
SyntaxErrors (
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ class ReplCompiler extends Compiler {
140
140
private def createUnit (defs : Definitions )(implicit ctx : Context ): CompilationUnit = {
141
141
val objectName = ctx.source.file.toString
142
142
assert(objectName.startsWith(str.REPL_SESSION_LINE ))
143
+ assert(objectName.endsWith(defs.state.objectIndex.toString))
143
144
val objectTermName = ctx.source.file.toString.toTermName
144
145
objectNames.update(defs.state.objectIndex, objectTermName)
145
146
@@ -236,7 +237,7 @@ class ReplCompiler extends Compiler {
236
237
PackageDef (Ident (nme.EMPTY_PACKAGE ), List (wrapper))
237
238
}
238
239
239
- ParseResult (expr) match {
240
+ ParseResult (expr)(state) match {
240
241
case Parsed (_, trees) =>
241
242
wrap(trees).result
242
243
case SyntaxErrors (_, reported, trees) =>
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ class ReplDriver(settings: Array[String],
113
113
implicit val ctx = state.context
114
114
try {
115
115
val line = terminal.readLine(completer)
116
- ParseResult (line)
116
+ ParseResult (line)(state)
117
117
} catch {
118
118
case _ : EndOfFileException |
119
119
_ : UserInterruptException => // Ctrl+D or Ctrl+C
@@ -132,7 +132,7 @@ class ReplDriver(settings: Array[String],
132
132
}
133
133
134
134
final def run (input : String )(implicit state : State ): State = withRedirectedOutput {
135
- val parsed = ParseResult (input)(state.context )
135
+ val parsed = ParseResult (input)(state)
136
136
interpret(parsed)
137
137
}
138
138
You can’t perform that action at this time.
0 commit comments