@@ -14,18 +14,19 @@ import typer.ForceDegree
1414import typer .Inferencing .isFullyDefined
1515import typer .RefChecks .{checkAllOverrides , checkSelfAgainstParents , OverridingPairsChecker }
1616import typer .Checking .{checkBounds , checkAppliedTypesIn }
17- import typer .ErrorReporting .{ Addenda , NothingToAdd , err }
17+ import typer .ErrorReporting .err
1818import typer .ProtoTypes .{LhsProto , WildcardSelectionProto , SelectionProto }
1919import util .{SimpleIdentitySet , EqHashMap , EqHashSet , SrcPos , Property }
2020import util .chaining .tap
2121import transform .{Recheck , PreRecheck , CapturedVars }
2222import Recheck .*
2323import scala .collection .mutable
24- import CaptureSet .{withCaptureSetsExplained , IncludeFailure , ExistentialSubsumesFailure , MutAdaptFailure }
24+ import CaptureSet .{withCaptureSetsExplained , IncludeFailure , MutAdaptFailure }
2525import CCState .*
2626import StdNames .nme
2727import NameKinds .{DefaultGetterName , WildcardParamName , UniqueNameKind }
2828import reporting .{trace , Message , OverrideError }
29+ import reporting .Message .Note
2930import Annotations .Annotation
3031import Capabilities .*
3132import Mutability .*
@@ -200,9 +201,6 @@ object CheckCaptures:
200201 && ! sym.isOneOf(DeferredOrTermParamOrAccessor )
201202 && ! sym.hasAnnotation(defn.UntrackedCapturesAnnot )
202203
203- private def ownerStr (owner : Symbol )(using Context ): String =
204- if owner.isAnonymousFunction then " enclosing function" else owner.show
205-
206204 trait CheckerAPI :
207205 /** Complete symbol info of a val or a def */
208206 def completeDef (tree : ValOrDefDef , sym : Symbol , completer : LazyType )(using Context ): Type
@@ -421,7 +419,7 @@ class CheckCaptures extends Recheck, SymTransformer:
421419 case (fail : IncludeFailure ) :: _ => fail.cs
422420 case _ => target
423421 def msg (provisional : Boolean ) =
424- def toAdd : String = errorNotes( otherNotes).toAdd .mkString
422+ def toAdd : String = otherNotes.map(_.render) .mkString
425423 def descr : String =
426424 val d = realTarget.description
427425 if d.isEmpty then provenance else " "
@@ -1246,7 +1244,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12461244 // too annoying. This is a hole since a defualt getter's result type
12471245 // might leak into a type variable.
12481246
1249- def fail (tree : Tree , expected : Type , addenda : Addenda ): Unit =
1247+ def fail (tree : Tree , expected : Type , notes : List [ Note ] ): Unit =
12501248 def maybeResult = if sym.is(Method ) then " result" else " "
12511249 report.error(
12521250 em """ $sym needs an explicit $maybeResult type because the inferred type does not conform to
@@ -1256,7 +1254,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12561254 | Externally visible type: $expected""" ,
12571255 tree.srcPos)
12581256
1259- def addenda (expected : Type ) = Addenda :
1257+ def addendum (expected : Type ) = Note :
12601258 def result = if tree.isInstanceOf [ValDef ] then " " else " result"
12611259 i """
12621260 |
@@ -1275,7 +1273,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12751273 val expected = tpt.tpe.dropAllRetains
12761274 todoAtPostCheck += { () =>
12771275 withCapAsRoot :
1278- testAdapted(tp, expected, tree.rhs, addenda (expected))(fail)
1276+ testAdapted(tp, expected, tree.rhs, addendum (expected) :: Nil )(fail)
12791277 // The check that inferred <: expected is done after recheck so that it
12801278 // does not interfere with normal rechecking by constraining capture set variables.
12811279 }
@@ -1482,34 +1480,27 @@ class CheckCaptures extends Recheck, SymTransformer:
14821480
14831481 type BoxErrors = mutable.ListBuffer [Message ] | Null
14841482
1485- private def errorNotes (notes : List [TypeComparer .ErrorNote ])(using Context ): Addenda =
1486- if notes.isEmpty then NothingToAdd
1487- else new Addenda :
1488- override def toAdd (using Context ) = notes.map: note =>
1489- i """
1490- |
1491- |Note that ${note.description}. """
1492-
14931483 /** Addendas for error messages that show where we have under-approximated by
1494- * mapping a a capability in contravariant position to the empty set because
1484+ * mapping of a capability in contravariant position to the empty set because
14951485 * the original result type of the map was not itself a capability.
14961486 */
1497- private def addApproxAddenda (using Context ) =
1498- new TypeAccumulator [ Addenda ] :
1499- def apply (add : Addenda , t : Type ) = t match
1487+ private def addApproxAddenda (using Context ): TypeAccumulator [ List [ Note ]] =
1488+ new TypeAccumulator :
1489+ def apply (notes : List [ Note ] , t : Type ) = t match
15001490 case CapturingType (t, CaptureSet .EmptyWithProvenance (ref, mapped)) =>
15011491 /* val (origCore, kind) = original match
15021492 case tp @ AnnotatedType(parent, ann) if ann.hasSymbol(defn.ReachCapabilityAnnot) =>
15031493 (parent, " deep")
15041494 case _ =>
15051495 (original, "")*/
1506- add ++ Addenda :
1496+ Note :
15071497 i """
15081498 |
15091499 |Note that a capability $ref in a capture set appearing in contravariant position
15101500 |was mapped to $mapped which is not a capability. Therefore, it was under-approximated to the empty set. """
1501+ :: notes
15111502 case _ =>
1512- foldOver(add , t)
1503+ foldOver(notes , t)
15131504
15141505 /** Massage `actual` and `expected` types before checking conformance.
15151506 * Massaging is done by the methods following this one:
@@ -1518,8 +1509,8 @@ class CheckCaptures extends Recheck, SymTransformer:
15181509 * If the resulting types are not compatible, try again with an actual type
15191510 * where local capture roots are instantiated to root variables.
15201511 */
1521- override def checkConformsExpr (actual : Type , expected : Type , tree : Tree , addenda : Addenda )(using Context ): Type =
1522- try testAdapted(actual, expected, tree, addenda )(err.typeMismatch)
1512+ override def checkConformsExpr (actual : Type , expected : Type , tree : Tree , notes : List [ Note ] )(using Context ): Type =
1513+ try testAdapted(actual, expected, tree, notes : List [ Note ] )(err.typeMismatch)
15231514 catch case ex : AssertionError =>
15241515 println(i " error while checking $tree: $actual against $expected" )
15251516 throw ex
@@ -1534,8 +1525,8 @@ class CheckCaptures extends Recheck, SymTransformer:
15341525 case _ => NoType
15351526 case _ => NoType
15361527
1537- inline def testAdapted (actual : Type , expected : Type , tree : Tree , addenda : Addenda )
1538- (fail : (Tree , Type , Addenda ) => Unit )(using Context ): Type =
1528+ inline def testAdapted (actual : Type , expected : Type , tree : Tree , notes : List [ Note ] )
1529+ (fail : (Tree , Type , List [ Note ] ) => Unit )(using Context ): Type =
15391530
15401531 var expected1 = alignDependentFunction(expected, actual.stripCapturing)
15411532 val falseDeps = expected1 ne expected
@@ -1582,11 +1573,12 @@ class CheckCaptures extends Recheck, SymTransformer:
15821573 }
15831574
15841575 TypeComparer .compareResult(tryCurrentType || tryWidenNamed) match
1585- case TypeComparer .CompareResult .Fail (notes ) =>
1576+ case TypeComparer .CompareResult .Fail (cmpNotes ) =>
15861577 capt.println(i " conforms failed for ${tree}: $actual vs $expected" )
15871578 if falseDeps then expected1 = unalignFunction(expected1)
1588- fail(tree.withType(actualBoxed), expected1,
1589- addApproxAddenda(addenda ++ errorNotes(notes), expected1))
1579+ val toAdd0 = notes ++ cmpNotes
1580+ val toAdd1 = addApproxAddenda(toAdd0, expected1)
1581+ fail(tree.withType(actualBoxed), expected1, toAdd1)
15901582 actual
15911583 case /* OK*/ _ =>
15921584 if debugSuccesses then tree match
0 commit comments