File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,12 @@ class ReplDriver(settings: Array[String],
254
254
def extractTopLevelImports (ctx : Context ): List [tpd.Import ] =
255
255
unfusedPhases(using ctx).collectFirst { case phase : CollectTopLevelImports => phase.imports }.get
256
256
257
+ def contextWithNewImports (ctx : Context , imports : List [tpd.Import ]): Context =
258
+ if imports.isEmpty then ctx
259
+ else
260
+ imports.foldLeft(ctx.fresh.setNewScope)((ctx, imp) =>
261
+ ctx.importContext(imp, imp.symbol(using ctx)))
262
+
257
263
implicit val state = {
258
264
val state0 = newRun(istate, parsed.reporter)
259
265
state0.copy(context = state0.context.withSource(parsed.source))
@@ -269,7 +275,10 @@ class ReplDriver(settings: Array[String],
269
275
var allImports = newState.imports
270
276
if (newImports.nonEmpty)
271
277
allImports += (newState.objectIndex -> newImports)
272
- val newStateWithImports = newState.copy(imports = allImports)
278
+ val newStateWithImports = newState.copy(
279
+ imports = allImports,
280
+ context = contextWithNewImports(newState.context, newImports)
281
+ )
273
282
274
283
val warnings = newState.context.reporter
275
284
.removeBufferedMessages(using newState.context)
Original file line number Diff line number Diff line change @@ -241,6 +241,27 @@ class ReplCompilerTests extends ReplTest:
241
241
assertEquals(List (" // defined class C" ), lines())
242
242
}
243
243
244
+ @ Test def i14491 =
245
+ initially {
246
+ run(" import language.experimental.fewerBraces" )
247
+ } andThen {
248
+ run(""" |val x = Seq(7,8,9).apply:
249
+ | 1
250
+ |""" .stripMargin)
251
+ assertEquals(" val x: Int = 8" , storedOutput().trim)
252
+ }
253
+ initially {
254
+ run(""" |import language.experimental.fewerBraces
255
+ |import language.experimental.fewerBraces as _
256
+ |""" .stripMargin)
257
+ } andThen {
258
+ run(""" |val x = Seq(7,8,9).apply:
259
+ | 1
260
+ |""" .stripMargin)
261
+ assert(" expected error if fewerBraces is unimported" ,
262
+ lines().exists(_.contains(" missing arguments for method apply" )))
263
+ }
264
+
244
265
object ReplCompilerTests :
245
266
246
267
private val pattern = Pattern .compile(" \\ r[\\ n]?|\\ n" );
You can’t perform that action at this time.
0 commit comments