Skip to content
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
// When the REPL creates a new run (ReplDriver.compile), parsing is already done in the old context, with the
// previous Run. Parser warnings were suspended in the old run and need to be copied over so they are not lost.
// Same as scala/scala/commit/79ca1408c7.
def initSuspendedMessages(oldRun: Run | Null) = if oldRun != null then
def initSuspendedMessages(oldRun: Run | Null) =
mySuspendedMessages.clear()
mySuspendedMessages ++= oldRun.mySuspendedMessages
if oldRun != null then
mySuspendedMessages ++= oldRun.mySuspendedMessages

def suppressionsComplete(source: SourceFile) = source == NoSource || mySuppressionsComplete(source)

Expand Down
6 changes: 2 additions & 4 deletions repl/src/dotty/tools/repl/ReplCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ReplCompiler extends Compiler:
)

def newRun(initCtx: Context, state: State): Run =
val run = new Run(this, initCtx) {
new Run(this, initCtx):
/** Import previous runs and user defined imports */
override protected def rootContext(using Context): Context = {
def importContext(imp: tpd.Import)(using Context) =
Expand All @@ -74,9 +74,7 @@ class ReplCompiler extends Compiler:
(state.validObjectIndexes).foldLeft(rootCtx)((ctx, id) =>
importPreviousRun(id)(using ctx))
}
}
run.suppressions.initSuspendedMessages(state.context.run)
run
.tap(_.suppressions.initSuspendedMessages(state.context.run))
end newRun

private def packaged(stats: List[untpd.Tree])(using Context): untpd.PackageDef =
Expand Down
62 changes: 31 additions & 31 deletions repl/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ class ReplDriver(settings: Array[String],
else state

case SyntaxErrors(_, errs, _) =>
// if there is a Run that is tracking suspended parse warnings, ignore (drop) them when erroring
if state.context.run != null then
state.context.run.suppressions.initSuspendedMessages(oldRun = null)
displayErrors(errs, state)

case CommandThenCode(cmd, code) =>
Expand Down Expand Up @@ -454,42 +457,39 @@ class ReplDriver(settings: Array[String],
displayErrors(errs, errState)
istate.afterFailedCompilation(errState.objectIndex)
,
{
case (unit: CompilationUnit, newState: State) =>
val newestWrapper = extractNewestWrapper(unit.untpdTree)
val newImports = extractTopLevelImports(newState.context)
var allImports = newState.imports
if (newImports.nonEmpty)
allImports += (newState.objectIndex -> newImports)
val newStateWithImports = newState.copy(
imports = allImports,
context = contextWithNewImports(newState.context, newImports)
)
(unit, newState) =>
val newestWrapper = extractNewestWrapper(unit.untpdTree)
val newImports = extractTopLevelImports(newState.context)
var allImports = newState.imports
if (newImports.nonEmpty)
allImports += (newState.objectIndex -> newImports)
val newStateWithImports = newState.copy(
imports = allImports,
context = contextWithNewImports(newState.context, newImports)
)

val warnings = newState.context.reporter
.removeBufferedMessages(using newState.context)
val warnings = newState.context.reporter
.removeBufferedMessages(using newState.context)

inContext(newState.context) {
val (updatedState, definitions) =
if (!ctx.settings.XreplDisableDisplay.value)
renderDefinitions(unit.tpdTree, newestWrapper)(using newStateWithImports)
else
(newStateWithImports, Seq.empty)
inContext(newState.context):
val (updatedState, definitions) =
if (!ctx.settings.XreplDisableDisplay.value)
renderDefinitions(unit.tpdTree, newestWrapper)(using newStateWithImports)
else
(newStateWithImports, Seq.empty)

// output is printed in the order it was put in. warnings should be
// shown before infos (eg. typedefs) for the same line. column
// ordering is mostly to make tests deterministic
given Ordering[Diagnostic] =
Ordering[(Int, Int, Int)].on(d => (d.pos.line, -d.level, d.pos.column))
// output is printed in the order it was put in. warnings should be
// shown before infos (e.g. typedefs) for the same line.
// column ordering is mostly to make tests deterministic
given Ordering[Diagnostic] =
Ordering[(Int, Int, Int)].on(d => (d.pos.line, -d.level, d.pos.column))

(if istate.quiet then warnings else definitions ++ warnings)
.sorted
.foreach(printDiagnostic)
(if istate.quiet then warnings else definitions ++ warnings)
.sorted
.foreach(printDiagnostic)

if updatedState.invalidObjectIndexes.contains(updatedState.objectIndex) then updatedState
else updatedState.recordInput(parsed.source.content().mkString)
}
}
if updatedState.invalidObjectIndexes.contains(updatedState.objectIndex) then updatedState
else updatedState.recordInput(parsed.source.content().mkString)
)
}

Expand Down
6 changes: 3 additions & 3 deletions repl/src/dotty/tools/repl/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ package repl
import dotc.reporting.{HideNonSensicalMessages, StoreReporter, UniqueMessagePositions}

/** Create empty outer store reporter */
private[repl] def newStoreReporter: StoreReporter =
new StoreReporter(null)
with UniqueMessagePositions with HideNonSensicalMessages
private[repl] def newStoreReporter: StoreReporter = ReplReporter()

private[repl] class ReplReporter extends StoreReporter(null), UniqueMessagePositions, HideNonSensicalMessages
2 changes: 1 addition & 1 deletion repl/test-resources/repl/10886
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ scala> type SelChannel[C <: Tuple] = C match { case x *: xs => x | SelChannel[xs
scala> lazy val a: SelChannel[("A", "B", "C")] = "A"
lazy val a: "A" | ("B" | ("C" | Nothing))

scala>:type a
scala> :type a
("A" : String) | (("B" : String) | (("C" : String) | Nothing))
6 changes: 3 additions & 3 deletions repl/test-resources/repl/1379
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
scala> object Foo { val bar = new Object { def baz = 1 }; bar.baz }
scala> object Foo { val bar = new Object { def baz = 1 }; bar.baz }
-- [E008] Not Found Error: -----------------------------------------------------
1 | object Foo { val bar = new Object { def baz = 1 }; bar.baz }
| ^^^^^^^
1 |object Foo { val bar = new Object { def baz = 1 }; bar.baz }
| ^^^^^^^
| value baz is not a member of Object
1 error found
6 changes: 3 additions & 3 deletions repl/test-resources/repl/commandPrefixes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
scala>:ty 123
scala> :ty 123
Int
scala>:type 123
scala> :type 123
Int
scala>:typee 123
scala> :typee 123
Unknown command: ":typee", run ":help" for a list of commands
84 changes: 42 additions & 42 deletions repl/test-resources/repl/errmsgs
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@ scala> class Inv[T](x: T)
// defined class Inv
scala> val x: List[String] = List(1)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val x: List[String] = List(1)
| ^
| Found: (1 : Int)
| Required: String
1 |val x: List[String] = List(1)
| ^
| Found: (1 : Int)
| Required: String
|
| longer explanation available when compiling with `-explain`
1 error found
scala> val y: List[List[String]] = List(List(1))
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val y: List[List[String]] = List(List(1))
| ^
| Found: (1 : Int)
| Required: String
1 |val y: List[List[String]] = List(List(1))
| ^
| Found: (1 : Int)
| Required: String
|
| longer explanation available when compiling with `-explain`
1 error found
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
| ^
| Found: (1 : Int)
| Required: String
1 |val z: (List[String], List[Int]) = (List(1), List("a"))
| ^
| Found: (1 : Int)
| Required: String
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
| ^^^
1 |val z: (List[String], List[Int]) = (List(1), List("a"))
| ^^^
| Found: ("a" : String)
| Required: Int
|
| longer explanation available when compiling with `-explain`
2 errors found
scala> val a: Inv[String] = new Inv(new Inv(1))
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val a: Inv[String] = new Inv(new Inv(1))
| ^^^^^^^^^^
| Found: Inv[Int]
| Required: String
1 |val a: Inv[String] = new Inv(new Inv(1))
| ^^^^^^^^^^
| Found: Inv[Int]
| Required: String
|
| longer explanation available when compiling with `-explain`
1 error found
scala> val b: Inv[String] = new Inv(1)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val b: Inv[String] = new Inv(1)
| ^
| Found: (1 : Int)
| Required: String
1 |val b: Inv[String] = new Inv(1)
| ^
| Found: (1 : Int)
| Required: String
|
| longer explanation available when compiling with `-explain`
1 error found
scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
1 |abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
|Found: (C.this.x : C.this.T)
|Required: T²
|
Expand All @@ -64,8 +64,8 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
1 |abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
|Found: (y : T)
|Required: T²
|
Expand All @@ -76,47 +76,47 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var
2 errors found
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
-- [E008] Not Found Error: -----------------------------------------------------
1 | class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
| ^^^^^^^^
1 |class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
| ^^^^^^^^
| value barr is not a member of Foo - did you mean foo.bar?
1 error found
scala> val x: List[Int] = "foo" :: List(1)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val x: List[Int] = "foo" :: List(1)
| ^^^^^
| Found: ("foo" : String)
| Required: Int
1 |val x: List[Int] = "foo" :: List(1)
| ^^^^^
| Found: ("foo" : String)
| Required: Int
|
| longer explanation available when compiling with `-explain`
1 error found
scala> while ((( foo ))) {}
-- [E006] Not Found Error: -----------------------------------------------------
1 | while ((( foo ))) {}
| ^^^
| Not found: foo
1 |while ((( foo ))) {}
| ^^^
| Not found: foo
|
| longer explanation available when compiling with `-explain`
1 error found
scala> val a: iDontExist = 1
-- [E006] Not Found Error: -----------------------------------------------------
1 | val a: iDontExist = 1
| ^^^^^^^^^^
| Not found: type iDontExist
1 |val a: iDontExist = 1
| ^^^^^^^^^^
| Not found: type iDontExist
|
| longer explanation available when compiling with `-explain`
1 error found
scala> def foo1(x: => Int) = x _
-- [E099] Syntax Error: --------------------------------------------------------
1 | def foo1(x: => Int) = x _
| ^^^
1 |def foo1(x: => Int) = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
|
| longer explanation available when compiling with `-explain`
1 error found
scala> def foo2(x: => Int): () => Int = x _
-- [E099] Syntax Error: --------------------------------------------------------
1 | def foo2(x: => Int): () => Int = x _
| ^^^
1 |def foo2(x: => Int): () => Int = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
|
| longer explanation available when compiling with `-explain`
Expand Down
8 changes: 4 additions & 4 deletions repl/test-resources/repl/i13208.default.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
scala> try 1
1 warning found
-- [E002] Syntax Warning: ------------------------------------------------------
1 | try 1
| ^^^^^
| A try without catch or finally is equivalent to putting
| its body in a block; no exceptions are handled.
1 |try 1
|^^^^^
|A try without catch or finally is equivalent to putting
|its body in a block; no exceptions are handled.
|
| longer explanation available when compiling with `-explain`
val res0: Int = 1
4 changes: 2 additions & 2 deletions repl/test-resources/repl/i1370
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
scala> object Lives { class Private { def foo1: Any = new Private.C1; def foo2: Any = new Private.C2 }; object Private { class C1 private {}; private class C2 {} } }
-- [E173] Reference Error: -----------------------------------------------------
1 | object Lives { class Private { def foo1: Any = new Private.C1; def foo2: Any = new Private.C2 }; object Private { class C1 private {}; private class C2 {} } }
| ^^^^^^^^^^
1 |object Lives { class Private { def foo1: Any = new Private.C1; def foo2: Any = new Private.C2 }; object Private { class C1 private {}; private class C2 {} } }
| ^^^^^^^^^^
|constructor C1 cannot be accessed as a member of Lives.Private.C1 from class Private.
| private constructor C1 can only be accessed from class C1 in object Private.
1 error found
8 changes: 4 additions & 4 deletions repl/test-resources/repl/i18383
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
scala>:settings -Wunused:all
scala> :settings -Wunused:all

scala> import scala.collection.*

scala> class Foo { import scala.util.*; println("foo") }
1 warning found
-- [E198] Unused Symbol Warning: -----------------------------------------------
1 | class Foo { import scala.util.*; println("foo") }
| ^
| unused import
1 |class Foo { import scala.util.*; println("foo") }
| ^
| unused import
// defined class Foo

scala> { import scala.util.*; "foo" }
Expand Down
14 changes: 7 additions & 7 deletions repl/test-resources/repl/i2063
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
scala> class Foo extends Bar // with one tab
-- [E006] Not Found Error: -----------------------------------------------------
1 | class Foo extends Bar // with one tab
| ^^^
| Not found: type Bar
1 | class Foo extends Bar // with one tab
| ^^^
| Not found: type Bar
|
| longer explanation available when compiling with `-explain`
1 error found
scala> class Foo extends Bar // with spaces
-- [E006] Not Found Error: -----------------------------------------------------
1 | class Foo extends Bar // with spaces
| ^^^
1 | class Foo extends Bar // with spaces
| ^^^
| Not found: type Bar
|
| longer explanation available when compiling with `-explain`
1 error found
scala> class Foo extends Bar // with tabs
-- [E006] Not Found Error: -----------------------------------------------------
1 | class Foo extends Bar // with tabs
| ^^^
1 | class Foo extends Bar // with tabs
| ^^^
| Not found: type Bar
|
| longer explanation available when compiling with `-explain`
Expand Down
4 changes: 2 additions & 2 deletions repl/test-resources/repl/i21655
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scala>:kind
The :kind command is not currently supported.
scala> :kind
The :kind command is not currently supported.
4 changes: 2 additions & 2 deletions repl/test-resources/repl/i21657
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scala>:sh
The :sh command is deprecated. Use `import scala.sys.process._` and `"command".!` instead.
scala> :sh
The :sh command is deprecated. Use `import scala.sys.process._` and `"command".!` instead.
Loading
Loading