From 8264638dd507601d085521c68598e8e7ebfe93c1 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Mon, 7 Oct 2024 23:21:30 +0200 Subject: [PATCH 1/2] Allow parsing global imports in REPL --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 ++-- compiler/src/dotty/tools/repl/ParseResult.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index d933e55a9823..e31086ffb958 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -4684,12 +4684,12 @@ object Parsers { * | Expr1 * | */ - def blockStatSeq(): List[Tree] = checkNoEscapingPlaceholders { + def blockStatSeq(allowGlobalImport: Boolean = false): List[Tree] = checkNoEscapingPlaceholders { val stats = new ListBuffer[Tree] while var empty = false if (in.token == IMPORT) - stats ++= importClause() + stats ++= importClause(outermost = allowGlobalImport) else if (isExprIntro) stats += expr(Location.InBlock) else if in.token == IMPLICIT && !in.inModifierPosition() then diff --git a/compiler/src/dotty/tools/repl/ParseResult.scala b/compiler/src/dotty/tools/repl/ParseResult.scala index b9139343bca1..867abf14af39 100644 --- a/compiler/src/dotty/tools/repl/ParseResult.scala +++ b/compiler/src/dotty/tools/repl/ParseResult.scala @@ -122,7 +122,7 @@ object ParseResult { private def parseStats(using Context): List[untpd.Tree] = { val parser = new Parser(ctx.source) - val stats = parser.blockStatSeq() + val stats = parser.blockStatSeq(allowGlobalImport = true) parser.accept(Tokens.EOF) stats } From 81e88dce8117c4e46a0ff91b9ff87165bdda8e6f Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Mon, 7 Oct 2024 23:21:46 +0200 Subject: [PATCH 2/2] Read capture checking settings from imports --- compiler/src/dotty/tools/dotc/config/Feature.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/config/Feature.scala b/compiler/src/dotty/tools/dotc/config/Feature.scala index ad20bab46c1e..54eaf15f2931 100644 --- a/compiler/src/dotty/tools/dotc/config/Feature.scala +++ b/compiler/src/dotty/tools/dotc/config/Feature.scala @@ -137,12 +137,14 @@ object Feature: /** Is pureFunctions enabled for this compilation unit? */ def pureFunsEnabled(using Context) = enabledBySetting(pureFunctions) + || enabledByImport(pureFunctions) || ctx.compilationUnit.knowsPureFuns || ccEnabled /** Is captureChecking enabled for this compilation unit? */ def ccEnabled(using Context) = enabledBySetting(captureChecking) + || enabledByImport(captureChecking) || ctx.compilationUnit.needsCaptureChecking /** Is pureFunctions enabled for any of the currently compiled compilation units? */