[m-rev.] for review: compare du types separately

Peter Wang novalazy at gmail.com
Tue Jul 28 12:33:15 AEST 2026


On Mon, 27 Jul 2026 13:34:12 +0200 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> 
> On Mon, 27 Jul 2026 15:41:24 +1000, Peter Wang <novalazy at gmail.com> wrote:
> > On Mon, 27 Jul 2026 00:34:29 +0200 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> > > --- a/tests/invalid/coerce_type_error.err_exp
> > > +++ b/tests/invalid/coerce_type_error.err_exp
> > > @@ -26,3 +26,10 @@ coerce_type_error.m:118:   error: cannot coerce `X' from
> > >  coerce_type_error.m:118:   `coerce_type_error.wrap_abs(coerce_type_error.citrus)'
> > >  coerce_type_error.m:118:   to
> > >  coerce_type_error.m:118:   `coerce_type_error.wrap_abs(coerce_type_error.fruit)'.
> > > +coerce_type_error.m:125: In clause for predicate `non_subtypes'/2:
> > > +coerce_type_error.m:125:   error: cannot coerce `Fruits' from
> > > +coerce_type_error.m:125:   `list.list(coerce_type_error.fruit)' to
> > > +coerce_type_error.m:125:   `list.list(coerce_type_error.orange_non_fruit)'.
> > > +coerce_type_error.m:125:   `coerce_type_error.fruit'/0 is not a subtype.
> > > +coerce_type_error.m:125:   `coerce_type_error.orange_non_fruit'/0 is not a
> > > +coerce_type_error.m:125:   subtype.
> > 
> > I think the last two sentences could mislead as to why the coercion is
> > invalid. Ideally, it would say something like: Neither `fruit' nor
> > `orange_non_fruit' is a subtype of the other.
> 
> I see two issues here.
> 
> The less important one is that at the moment, each "X is not a subtype"
> is a separate coerce_fail that is discovered independently, so replacing two of those
> with one message will require post-processing the list of coerce_fails.
> Since we already do this (in another form), this is a minor annoyance.
> 
> The more significant issue is that "fruit is not a subtype" is a stronger statement
> than "fruit is not a subtype of orange_non_fruit", and therefore it gives
> more info to the user. I happen to think that extra info may be useful,
> at least sometimes. If you don't think so, can you please tell me your reason.

The issue is that neither "fruit is not a subtype" or "orange_non_fruit
is not a subtype" are, by themselves, the reason for the coercion to be
invalid. But since the statements follow the error message, a reader
may be misled into thinking "list(T) can only be coerced when T is a
subtype".

Peter


More information about the reviews mailing list