[m-rev.] for review: infrastructure for diagnosing coerce failures
Zoltan Somogyi
zoltan.somogyi at runbox.com
Mon Jul 20 05:43:10 AEST 2026
For review by Peter.
Peter, would you object if I move the test for both from-type and to-type
being du types up the call chain as far as it is possible to move them?
I think it could simplify both the main checking code and the error handling.
I think it would also simplify the next change I would like to make.
At the moment, if you can coerce from a subtype tsub to its sypertype t, then
- you can coerce from list(tsub) to list(t), but
- you cannot coerce from one_or_more(tsub) to one_or_more(t).
This violates the law of least astonishment: why can you coerce list(tsub)
when it occurs on its own, but not when it occurs as a functor arg?
The cause is that acc_invariant_tvars_in_ctor_rhs_type treats a functor arg
whose type_ctor/type_param list is the same as the type_ctor/type_param list
of whole term (such as the second arg of [|]) differently from a functor arg
for which is not true (such as the second arg of one_or_more).
I would propose that when TypeCtor != BaseTypeCtor, the
acc_invariant_tvars_in_ctor_rhs_type predicate should be allow to descend
into the definition of Typector, provided that TypeCtor is
(a) a du type and
(b) not on the stack of BaseTypeCtor/BaseTypeParam pairs that
the current call's ancestors were invoked with.
This would go with the generalization of TypeCtor = BaseTypeCtor test
to a test that checks whether TypeCtor appear in that stack of pairs,
with ArgTypes being tested against the matching BaseTypeParams.
Can you see any reason why this wouldn't work? Do you know of any
research relevant to this issue?
Zoltan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.coe
Type: application/octet-stream
Size: 867 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20260719/d978be12/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.coe
Type: application/octet-stream
Size: 37850 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20260719/d978be12/attachment-0003.obj>
More information about the reviews
mailing list