Skip to content

Commit a47aaf0

Browse files
committed
Changes in compiler to work with capture checking
1 parent 5e2e34b commit a47aaf0

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

tests/pos-with-compiler-cc/dotc/report.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import config.SourceVersion
99
import ast._
1010
import config.Feature.sourceVersion
1111
import java.lang.System.currentTimeMillis
12-
12+
import language.experimental.pureFunctions
1313

1414
object report:
1515

1616
/** For sending messages that are printed only if -verbose is set */
17-
def inform(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
17+
def inform(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
1818
if ctx.settings.verbose.value then echo(msg, pos)
1919

20-
def echo(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
20+
def echo(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
2121
ctx.reporter.report(new Info(msg.toMessage, pos.sourcePos))
2222

2323
private def issueWarning(warning: Warning)(using Context): Unit =
@@ -26,28 +26,28 @@ object report:
2626
def deprecationWarning(msg: Message, pos: SrcPos)(using Context): Unit =
2727
issueWarning(new DeprecationWarning(msg, pos.sourcePos))
2828

29-
def deprecationWarning(msg: => String, pos: SrcPos)(using Context): Unit =
29+
def deprecationWarning(msg: -> String, pos: SrcPos)(using Context): Unit =
3030
deprecationWarning(msg.toMessage, pos)
3131

3232
def migrationWarning(msg: Message, pos: SrcPos)(using Context): Unit =
3333
issueWarning(new MigrationWarning(msg, pos.sourcePos))
3434

35-
def migrationWarning(msg: => String, pos: SrcPos)(using Context): Unit =
35+
def migrationWarning(msg: -> String, pos: SrcPos)(using Context): Unit =
3636
migrationWarning(msg.toMessage, pos)
3737

3838
def uncheckedWarning(msg: Message, pos: SrcPos)(using Context): Unit =
3939
issueWarning(new UncheckedWarning(msg, pos.sourcePos))
4040

41-
def uncheckedWarning(msg: => String, pos: SrcPos)(using Context): Unit =
41+
def uncheckedWarning(msg: -> String, pos: SrcPos)(using Context): Unit =
4242
uncheckedWarning(msg.toMessage, pos)
4343

4444
def featureWarning(msg: Message, pos: SrcPos)(using Context): Unit =
4545
issueWarning(new FeatureWarning(msg, pos.sourcePos))
4646

47-
def featureWarning(msg: => String, pos: SrcPos)(using Context): Unit =
47+
def featureWarning(msg: -> String, pos: SrcPos)(using Context): Unit =
4848
featureWarning(msg.toMessage, pos)
4949

50-
def featureWarning(feature: String, featureDescription: => String,
50+
def featureWarning(feature: String, featureDescription: -> String,
5151
featureUseSite: Symbol, required: Boolean, pos: SrcPos)(using Context): Unit = {
5252
val req = if (required) "needs to" else "should"
5353
val fqname = s"scala.language.$feature"
@@ -70,15 +70,15 @@ object report:
7070
def warning(msg: Message, pos: SrcPos)(using Context): Unit =
7171
issueWarning(new Warning(msg, addInlineds(pos)))
7272

73-
def warning(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
73+
def warning(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
7474
warning(msg.toMessage, pos)
7575

7676
def error(msg: Message, pos: SrcPos)(using Context): Unit =
7777
val fullPos = addInlineds(pos)
7878
ctx.reporter.report(new Error(msg, fullPos))
7979
if ctx.settings.YdebugError.value then Thread.dumpStack()
8080

81-
def error(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
81+
def error(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
8282
error(msg.toMessage, pos)
8383

8484
def error(ex: TypeError, pos: SrcPos)(using Context): Unit =
@@ -91,14 +91,14 @@ object report:
9191
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
9292
else error(msg, pos)
9393

94-
def errorOrMigrationWarning(msg: => String, pos: SrcPos, from: SourceVersion)(using Context): Unit =
94+
def errorOrMigrationWarning(msg: -> String, pos: SrcPos, from: SourceVersion)(using Context): Unit =
9595
errorOrMigrationWarning(msg.toMessage, pos, from)
9696

9797
def gradualErrorOrMigrationWarning(msg: Message, pos: SrcPos, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
9898
if sourceVersion.isAtLeast(errorFrom) then errorOrMigrationWarning(msg, pos, errorFrom)
9999
else if sourceVersion.isAtLeast(warnFrom) then warning(msg, pos)
100100

101-
def gradualErrorOrMigrationWarning(msg: => String, pos: SrcPos, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
101+
def gradualErrorOrMigrationWarning(msg: -> String, pos: SrcPos, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
102102
gradualErrorOrMigrationWarning(msg.toMessage, pos, warnFrom, errorFrom)
103103

104104
def restrictionError(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
@@ -111,27 +111,27 @@ object report:
111111
* See [[config.CompilerCommand#explainAdvanced]] for the exact meaning of
112112
* "contains" here.
113113
*/
114-
def log(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
114+
def log(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
115115
if (ctx.settings.Ylog.value.containsPhase(ctx.phase))
116116
echo(s"[log ${ctx.phase}] $msg", pos)
117117

118-
def debuglog(msg: => String)(using Context): Unit =
118+
def debuglog(msg: -> String)(using Context): Unit =
119119
if (ctx.debug) log(msg)
120120

121-
def informTime(msg: => String, start: Long)(using Context): Unit = {
121+
def informTime(msg: -> String, start: Long)(using Context): Unit = {
122122
def elapsed = s" in ${currentTimeMillis - start}ms"
123123
informProgress(msg + elapsed)
124124
}
125125

126-
def informProgress(msg: => String)(using Context): Unit =
126+
def informProgress(msg: -> String)(using Context): Unit =
127127
inform("[" + msg + "]")
128128

129-
def logWith[T](msg: => String)(value: T)(using Context): T = {
129+
def logWith[T](msg: -> String)(value: T)(using Context): T = {
130130
log(msg + " " + value)
131131
value
132132
}
133133

134-
def debugwarn(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
134+
def debugwarn(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
135135
if (ctx.settings.Ydebug.value) warning(msg, pos)
136136

137137
private def addInlineds(pos: SrcPos)(using Context): SourcePosition =

tests/pos-with-compiler-cc/dotc/reporting/Diagnostic.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import dotty.tools.dotc.util.SourcePosition
1212
import java.util.Optional
1313
import scala.util.chaining._
1414
import core.Decorators.toMessage
15+
import language.experimental.pureFunctions
1516

1617
object Diagnostic:
1718

@@ -25,7 +26,7 @@ object Diagnostic:
2526
msg: Message,
2627
pos: SourcePosition
2728
) extends Diagnostic(msg, pos, ERROR):
28-
def this(str: => String, pos: SourcePosition) = this(str.toMessage, pos)
29+
def this(str: -> String, pos: SourcePosition) = this(str.toMessage, pos)
2930

3031
/** A sticky error is an error that should not be hidden by backtracking and
3132
* trying some alternative path. Typically, errors issued after catching
@@ -49,7 +50,7 @@ object Diagnostic:
4950
msg: Message,
5051
pos: SourcePosition
5152
) extends Diagnostic(msg, pos, INFO):
52-
def this(str: => String, pos: SourcePosition) = this(str.toMessage, pos)
53+
def this(str: -> String, pos: SourcePosition) = this(str.toMessage, pos)
5354

5455
abstract class ConditionalWarning(
5556
msg: Message,

tests/pos-with-compiler-cc/dotc/reporting/Message.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ package reporting
44

55
import core.Contexts.*, core.Decorators.*, core.Mode
66
import config.SourceVersion
7-
87
import scala.language.unsafeNulls
9-
108
import scala.annotation.threadUnsafe
9+
import language.experimental.pureFunctions
1110

1211
object Message {
1312
val nonSensicalStartTag: String = "<nonsensical>"
@@ -119,15 +118,15 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
119118
override val canExplain = self.canExplain
120119
}
121120

122-
def append(suffix: => String): Message = mapMsg(_ ++ suffix)
121+
def append(suffix: -> String): Message = mapMsg(_ ++ suffix)
123122

124-
def mapMsg(f: String => String): Message = new Message(errorId):
123+
def mapMsg(f: String -> String): Message = new Message(errorId):
125124
val kind = self.kind
126125
def msg = f(self.msg)
127126
def explain = self.explain
128127
override def canExplain = self.canExplain
129128

130-
def appendExplanation(suffix: => String): Message = new Message(errorId):
129+
def appendExplanation(suffix: -> String): Message = new Message(errorId):
131130
val kind = self.kind
132131
def msg = self.msg
133132
def explain = self.explain ++ suffix
@@ -144,7 +143,7 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
144143
}
145144

146145
/** The fallback `Message` containing no explanation and having no `kind` */
147-
class NoExplanation(msgFn: => String) extends Message(ErrorMessageID.NoExplanationID) {
146+
class NoExplanation(msgFn: -> String) extends Message(ErrorMessageID.NoExplanationID) {
148147
def msg: String = msgFn
149148
def explain: String = ""
150149
val kind: MessageKind = MessageKind.NoKind

tests/pos-with-compiler-cc/dotc/reporting/Reporter.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import dotty.tools.dotc.core.Symbols.{NoSymbol, Symbol}
1010
import dotty.tools.dotc.reporting.Diagnostic._
1111
import dotty.tools.dotc.reporting.Message._
1212
import dotty.tools.dotc.util.NoSourcePosition
13+
import core.Decorators.toMessage
1314

1415
import java.io.{BufferedReader, PrintWriter}
1516
import scala.annotation.internal.sharable
1617
import scala.collection.mutable
17-
import core.Decorators.toMessage
18+
import scala.caps.unsafeUnbox
1819

1920
object Reporter {
2021
/** Convert a SimpleReporter into a real Reporter */
@@ -31,7 +32,7 @@ object Reporter {
3132

3233
type ErrorHandler = (Diagnostic, Context) => Unit
3334

34-
private val defaultIncompleteHandler: ErrorHandler =
35+
private val defaultIncompleteHandler: (Diagnostic, Context) -> Unit =
3536
(mc, ctx) => ctx.reporter.report(mc)(using ctx)
3637

3738
/** Show prompt if `-Xprompt` is passed as a flag to the compiler */
@@ -84,13 +85,14 @@ abstract class Reporter extends interfaces.ReporterResult {
8485
private var incompleteHandler: ErrorHandler = defaultIncompleteHandler
8586

8687
def withIncompleteHandler[T](handler: ErrorHandler)(op: => T): T = {
87-
val saved = incompleteHandler
88+
val saved = incompleteHandler.unsafeUnbox
8889
incompleteHandler = handler
8990
try op
9091
finally incompleteHandler = saved
9192
}
9293

93-
private def isIncompleteChecking = incompleteHandler ne defaultIncompleteHandler
94+
private def isIncompleteChecking =
95+
incompleteHandler.unsafeUnbox ne defaultIncompleteHandler
9496

9597
private var _errorCount = 0
9698
private var _warningCount = 0
@@ -203,7 +205,7 @@ abstract class Reporter extends interfaces.ReporterResult {
203205
def report(dia: Diagnostic)(using Context): Unit = issueIfNotSuppressed(dia)
204206

205207
def incomplete(dia: Diagnostic)(using Context): Unit =
206-
incompleteHandler(dia, ctx)
208+
incompleteHandler.unsafeUnbox(dia, ctx)
207209

208210
/** Summary of warnings and errors */
209211
def summary: String = {

0 commit comments

Comments
 (0)