Files
mercury/tests/invalid/coerce_void.err_exp
Peter Wang 6094f27850 Fix bug with typechecking of coercions.
Fix a problem where the order that the coercions are typechecked
can cause type variables to be bound differently.

For example, assuming citrus =< fruit:

    X = [] : list(T),
    coerce(X) = _ : list(fruit),
    coerce(X) = _ : list(citrus)

T could end up bound to either 'fruit' or 'citrus' depending on which
coercion is checked first, due to unification of the type variable in
the coerce argument type, and the target type of the coercion.
This is clearly wrong. Moreover, there is no reason that 'fruit' and
'citrus' are the only possibilities for T; there could be another
subtype for 'fruit' as well.

The fix here is to delay checking of any coercion until its argument
type is resolved, and to reject any coercion whose argument type
remains unresolved.

compiler/type_assign.m:
    Add status for coercion that could not be satisfied due to an
    unresolved type.

    Fix a comment.

compiler/typecheck_clauses.m:
    When checking coerce constraints after typechecking a clause,
    keep delaying any coercions with a non-ground "from" type.
    This prevents the problem, which is that a type variable in the
    "from" type of a coercion is unified with a type from the "to" type,
    affecting coercions processed later which also would bind the same
    type variable.

    If we cannot make progress on a set of delayed coercions, then mark
    all those coercions as not-yet-resolved.

compiler/typecheck.m:
    Generate errors for coercions with unresolved types.

compiler/typecheck_errors.m:
    Add predicate for reporting coercions with unresolved types.

    Add "error:" prefix to invalid coercion errors.

tests/invalid/coerce_ambig.m
    Delete out-of-date comments.

tests/invalid/coerce_ambig.err_exp
tests/invalid/coerce_infer.err_exp
tests/invalid/coerce_non_du.err_exp
tests/invalid/coerce_type_error.err_exp
tests/invalid/coerce_unify_tvars.err_exp
tests/invalid/coerce_void.err_exp
    Update expected outputs.
2024-07-02 16:29:12 +10:00

229 B

coerce_void.m:019: In clause for predicate `main'/2:
coerce_void.m:019: error: the type of `V_8' is unresolved; cannot coerce from
coerce_void.m:019: `list.list(V_2)' to `list.list(V_1)'.