Skip to content

Fix parsing crash for update in later phases #23390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object Feature:
/** Is captureChecking enabled for this compilation unit? */
def ccEnabled(using Context) =
enabledBySetting(captureChecking)
|| ctx.compilationUnit.needsCaptureChecking
|| ctx.originalCompilationUnit.needsCaptureChecking

/** Is pureFunctions enabled for any of the currently compiled compilation units? */
def pureFunsEnabledSomewhere(using Context) =
Expand Down
15 changes: 11 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import plugins.*
import java.util.concurrent.atomic.AtomicInteger
import java.nio.file.InvalidPathException
import dotty.tools.dotc.coverage.Coverage
import scala.annotation.tailrec

object Contexts {

Expand Down Expand Up @@ -776,6 +777,14 @@ object Contexts {
c
end FreshContext

extension (ctx: Context)
/** Get the original compilation unit, ignoring any highlighting wrappers. */
@tailrec
def originalCompilationUnit: CompilationUnit =
val cu = ctx.compilationUnit
if cu.source.name == SyntaxHighlighting.VirtualSourceName then ctx.outer.originalCompilationUnit
else cu

extension (c: Context)
def addNotNullInfo(info: NotNullInfo) =
if c.explicitNulls then c.withNotNullInfos(c.notNullInfos.extendWith(info)) else c
Expand All @@ -787,18 +796,16 @@ object Contexts {
if !c.explicitNulls || (c.notNullInfos eq infos) then c else c.fresh.setNotNullInfos(infos)

// TODO: Fix issue when converting ModeChanges and FreshModeChanges to extension givens
extension (c: Context) {
extension (c: Context)
final def withModeBits(mode: Mode): Context =
if (mode != c.mode) c.fresh.setMode(mode) else c

final def addMode(mode: Mode): Context = withModeBits(c.mode | mode)
final def retractMode(mode: Mode): Context = withModeBits(c.mode &~ mode)
}

extension (c: FreshContext) {
extension (c: FreshContext)
final def addMode(mode: Mode): c.type = c.setMode(c.mode | mode)
final def retractMode(mode: Mode): c.type = c.setMode(c.mode &~ mode)
}

/** Run `op` with a pool-allocated context that has an ExporeTyperState. */
inline def explore[T](inline op: Context ?=> T)(using Context): T =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import java.util.Arrays
/** This object provides functions for syntax highlighting in the REPL */
object SyntaxHighlighting {

/** The name of the virtual source file used for highlighting */
val VirtualSourceName = "<highlighting>"

/** if true, log erroneous positions being highlighted */
private inline val debug = true

Expand All @@ -33,7 +36,7 @@ object SyntaxHighlighting {
def freshCtx = ctx.fresh.setReporter(Reporter.NoReporter)
if (in.isEmpty || ctx.settings.color.value == "never") in
else {
val source = SourceFile.virtual("<highlighting>", in)
val source = SourceFile.virtual(VirtualSourceName, in)

given Context = freshCtx
.setCompilationUnit(CompilationUnit(source, mustExist = false)(using freshCtx))
Expand Down
8 changes: 8 additions & 0 deletions tests/neg-custom-args/captures/i23389-1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import language.experimental.captureChecking
import caps.*

trait Collection[+T] extends Mutable:
update def add(elem: T): Unit // error
update def remove(elem: T): Unit // error
def get(index: Int): Option[T]

8 changes: 8 additions & 0 deletions tests/neg-custom-args/captures/i23389-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import language.experimental.captureChecking
import caps.*

trait Collection[T] extends Mutable // <- note the forgotten :
update def add(elem: T): Unit // error // error
update def remove(elem: T): Unit // error // error
def get(index: Int): Option[T] // error // error

Loading