@@ -14,7 +14,7 @@ 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 .{Note , err }
1818import typer .ProtoTypes .{LhsProto , WildcardSelectionProto , SelectionProto }
1919import util .{SimpleIdentitySet , EqHashMap , EqHashSet , SrcPos , Property }
2020import util .chaining .tap
@@ -399,7 +399,7 @@ class CheckCaptures extends Recheck, SymTransformer:
399399 case (fail : IncludeFailure ) :: _ => fail.cs
400400 case _ => target
401401 def msg (provisional : Boolean ) =
402- def toAdd : String = errorNotes(otherNotes).toAdd .mkString
402+ def toAdd : String = errorNotes(otherNotes).map(_.render) .mkString
403403 def descr : String =
404404 val d = realTarget.description
405405 if d.isEmpty then provenance else " "
@@ -1208,7 +1208,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12081208 // too annoying. This is a hole since a defualt getter's result type
12091209 // might leak into a type variable.
12101210
1211- def fail (tree : Tree , expected : Type , addenda : Addenda ): Unit =
1211+ def fail (tree : Tree , expected : Type , notes : List [ Note ] ): Unit =
12121212 def maybeResult = if sym.is(Method ) then " result" else " "
12131213 report.error(
12141214 em """ $sym needs an explicit $maybeResult type because the inferred type does not conform to
@@ -1218,7 +1218,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12181218 | Externally visible type: $expected""" ,
12191219 tree.srcPos)
12201220
1221- def addenda (expected : Type ) = Addenda :
1221+ def addendum (expected : Type ) = Note :
12221222 def result = if tree.isInstanceOf [ValDef ] then " " else " result"
12231223 i """
12241224 |
@@ -1237,7 +1237,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12371237 val expected = tpt.tpe.dropAllRetains
12381238 todoAtPostCheck += { () =>
12391239 withCapAsRoot :
1240- testAdapted(tp, expected, tree.rhs, addenda (expected))(fail)
1240+ testAdapted(tp, expected, tree.rhs, addendum (expected) :: Nil )(fail)
12411241 // The check that inferred <: expected is done after recheck so that it
12421242 // does not interfere with normal rechecking by constraining capture set variables.
12431243 }
@@ -1444,34 +1444,34 @@ class CheckCaptures extends Recheck, SymTransformer:
14441444
14451445 type BoxErrors = mutable.ListBuffer [Message ] | Null
14461446
1447- private def errorNotes (notes : List [TypeComparer .ErrorNote ])(using Context ): Addenda =
1448- if notes.isEmpty then NothingToAdd
1449- else new Addenda :
1450- override def toAdd (using Context ) = notes.map: note =>
1447+ private def errorNotes (notes : List [TypeComparer .ErrorNote ])(using Context ): List [Note ] =
1448+ notes.map: note =>
1449+ Note :
14511450 i """
14521451 |
14531452 |Note that ${note.description}. """
14541453
14551454 /** Addendas for error messages that show where we have under-approximated by
1456- * mapping a a capability in contravariant position to the empty set because
1455+ * mapping of a capability in contravariant position to the empty set because
14571456 * the original result type of the map was not itself a capability.
14581457 */
1459- private def addApproxAddenda (using Context ) =
1460- new TypeAccumulator [ Addenda ] :
1461- def apply (add : Addenda , t : Type ) = t match
1458+ private def addApproxAddenda (using Context ): TypeAccumulator [ List [ Note ]] =
1459+ new TypeAccumulator :
1460+ def apply (notes : List [ Note ] , t : Type ) = t match
14621461 case CapturingType (t, CaptureSet .EmptyWithProvenance (ref, mapped)) =>
14631462 /* val (origCore, kind) = original match
14641463 case tp @ AnnotatedType(parent, ann) if ann.hasSymbol(defn.ReachCapabilityAnnot) =>
14651464 (parent, " deep")
14661465 case _ =>
14671466 (original, "")*/
1468- add ++ Addenda :
1467+ Note :
14691468 i """
14701469 |
14711470 |Note that a capability $ref in a capture set appearing in contravariant position
14721471 |was mapped to $mapped which is not a capability. Therefore, it was under-approximated to the empty set. """
1472+ :: notes
14731473 case _ =>
1474- foldOver(add , t)
1474+ foldOver(notes , t)
14751475
14761476 /** Massage `actual` and `expected` types before checking conformance.
14771477 * Massaging is done by the methods following this one:
@@ -1480,8 +1480,8 @@ class CheckCaptures extends Recheck, SymTransformer:
14801480 * If the resulting types are not compatible, try again with an actual type
14811481 * where local capture roots are instantiated to root variables.
14821482 */
1483- override def checkConformsExpr (actual : Type , expected : Type , tree : Tree , addenda : Addenda )(using Context ): Type =
1484- try testAdapted(actual, expected, tree, addenda )(err.typeMismatch)
1483+ override def checkConformsExpr (actual : Type , expected : Type , tree : Tree , notes : List [ Note ] )(using Context ): Type =
1484+ try testAdapted(actual, expected, tree, notes : List [ Note ] )(err.typeMismatch)
14851485 catch case ex : AssertionError =>
14861486 println(i " error while checking $tree: $actual against $expected" )
14871487 throw ex
@@ -1496,8 +1496,8 @@ class CheckCaptures extends Recheck, SymTransformer:
14961496 case _ => NoType
14971497 case _ => NoType
14981498
1499- inline def testAdapted (actual : Type , expected : Type , tree : Tree , addenda : Addenda )
1500- (fail : (Tree , Type , Addenda ) => Unit )(using Context ): Type =
1499+ inline def testAdapted (actual : Type , expected : Type , tree : Tree , notes : List [ Note ] )
1500+ (fail : (Tree , Type , List [ Note ] ) => Unit )(using Context ): Type =
15011501
15021502 var expected1 = alignDependentFunction(expected, actual.stripCapturing)
15031503 val falseDeps = expected1 ne expected
@@ -1544,11 +1544,12 @@ class CheckCaptures extends Recheck, SymTransformer:
15441544 }
15451545
15461546 TypeComparer .compareResult(tryCurrentType || tryWidenNamed) match
1547- case TypeComparer .CompareResult .Fail (notes ) =>
1547+ case TypeComparer .CompareResult .Fail (errNotes ) =>
15481548 capt.println(i " conforms failed for ${tree}: $actual vs $expected" )
15491549 if falseDeps then expected1 = unalignFunction(expected1)
1550- fail(tree.withType(actualBoxed), expected1,
1551- addApproxAddenda(addenda ++ errorNotes(notes), expected1))
1550+ val toAdd0 = notes ++ errorNotes(errNotes)
1551+ val toAdd1 = addApproxAddenda(toAdd0, expected1)
1552+ fail(tree.withType(actualBoxed), expected1, toAdd1)
15521553 actual
15531554 case /* OK*/ _ =>
15541555 if debugSuccesses then tree match
0 commit comments