Open Calvin-L opened 2 months ago
(Related, although less important: with the @PolyMustCall
annotations in place, the Checker Framework reports some spurious warnings like
Handle.java:[13,38] [mustcallalias.method.return.and.param] @MustCallAlias annotations must appear in pairs (one on a return type and one on a parameter type).
But no parameter has a @MustCallAlias annotation, even though the return type is annotated with @MustCallAlias
I suspect it is not checking the implicit this
parameter.)
(On that note, would @MustCallAlias
be more precise than @PolyMustCall
in my example?)
I recently encountered some code structured like this:
Checker Framework 3.47.0 reports
Fair enough:
Handle
is@MustCall("close")
, so you can't return aHandle
in place of an@MustCall({}) Interface
.But this code is safe. It is even possible to annotate correctly, but doing so is very awkward:
Because the method returns
this
, its return value must have the same@MustCall
as the receiver. With the additional@PolyMustCall
annotations, the Checker Framework approves.Is it possible to adjust the MustCall defaulting rules to do this automatically for methods returning
@This
?(Actually, this probably generalizes to other type systems, but I expect it will be most useful for the MustCall checker.)