Skip to content

Commit cce8509

Browse files
committed
More refactoring, avoid globally accessible variable
1 parent a6fcc72 commit cce8509

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

+18-14
Original file line numberDiff line numberDiff line change
@@ -1083,10 +1083,15 @@ object CaptureSet:
10831083
*/
10841084
case class ExistentialSubsumesFailure(val ex: root.Result, val other: CaptureRef) extends ErrorNote
10851085

1086-
enum CompareResult extends Showable:
1087-
case OK
1088-
case Fail(trace: List[CaptureSet])
1089-
case LevelError(cs: CaptureSet, elem: CaptureRef) extends CompareResult, ErrorNote
1086+
trait AcceptsNotes extends CompareResult:
1087+
protected var myErrorNotes: List[ErrorNote] = Nil
1088+
override def errorNotes: List[ErrorNote] = myErrorNotes
1089+
override def withNotes(notes: List[ErrorNote]): CompareResult =
1090+
myErrorNotes = notes
1091+
this
1092+
1093+
class CompareResult extends Showable:
1094+
import CompareResult.*
10901095

10911096
override def toText(printer: Printer): Text =
10921097
inContext(printer.printerContext):
@@ -1111,16 +1116,6 @@ object CaptureSet:
11111116
case result: LevelError => Some(result)
11121117
case _ => None
11131118

1114-
private var myErrorNotes: List[ErrorNote] = Nil
1115-
1116-
def errorNotes: List[ErrorNote] = myErrorNotes
1117-
1118-
def withNotes(notes: List[ErrorNote]): CompareResult = this match
1119-
case OK => OK
1120-
case _ =>
1121-
myErrorNotes = notes
1122-
this
1123-
11241119
inline def andAlso(op: Context ?=> CompareResult)(using Context): CompareResult =
11251120
if isOK then op else this
11261121

@@ -1134,6 +1129,15 @@ object CaptureSet:
11341129
inline def addToTrace(cs: CaptureSet): CompareResult = this match
11351130
case Fail(trace) => Fail(cs :: trace)
11361131
case _ => this
1132+
1133+
def errorNotes: List[ErrorNote] = Nil
1134+
def withNotes(notes: List[ErrorNote]): CompareResult = this
1135+
1136+
object CompareResult:
1137+
val OK: CompareResult = new CompareResult:
1138+
override def toString = "OK"
1139+
case class Fail(trace: List[CaptureSet]) extends CompareResult, AcceptsNotes
1140+
case class LevelError(cs: CaptureSet, elem: CaptureRef) extends CompareResult, AcceptsNotes, ErrorNote
11371141
end CompareResult
11381142

11391143
/** A VarState serves as a snapshot mechanism that can undo

0 commit comments

Comments
 (0)