Files
mercury/tests/invalid/no_method.err_exp
Zoltan Somogyi bc1bf0470f Get type_to_pieces to generate structured output.
compiler/error_util.m:
    Rewrite the type_to_pieces function, which typecheck_errors.m uses
    to format types in error messages, in order to fix five problems.

    The first two problems were with formatting higher order types.
    First, if a higher order type included an existentially quantified
    type variable, that quantification was *not* printed around the
    higher order type. Second, that quantification *was* printed around
    the type of every (non-higher-order) argument of the higher order value.
    The only reason why this has not been a problem so far is that
    we have no test case that contains a higher order type with an
    existentially quantified type variable :-(

    The fix to both these problems is to always put the existential
    quantification of any such type variables at the top level, regardless
    of the kind of type the quantification ranges over, and to never print
    any quantification of any of its component types.

    The third problem was that non-higher-order types were output in a
    non-structured fashion. (The special-case code we used to format
    higher order types did already output *them* in a structured fashion,
    though only at the top level.) We did this by converting (unparsing)
    the type to a term, and then calling mercury_term_to_string.

    Generating structured output by replacing only the mercury_term_to_string
    part would not worked well; most of the code would have been devoted
    to working out what kind of type the given term was representing.
    Therefore this diff changes the approach to formatting types without
    converting them to a term. The output we generate for each type
    uses indentation levels to show the type's structure, but for
    types whose formatted form is sufficiently short, we delete all
    the newlines from that representation.

    The fourth problem was while most of the existing code took care
    to treat function names as unbreakable, one part of it did not,
    which caused the name of a field update function, "f1 :=",
    to be split across two lines. This diff fixes that bug as well.

    A fifth problem, pointed out by Peter, was that we were printing
    arity-0 functions as "func" instead of as "(func)", even though
    Mercury syntax for types demands the latter.

    An arguable sixth problem was that we formatted existential
    quantifications as
        (some [Vars] Type)
    We now format that as
        some [Vars] (Type)

    Change the order of the arguments of type_to_pieces to reduce
    the difference between it and type_pieces, its internal version,
    which we use to format types that do not need existential quantification.

    Export the function that filters newlines out of lists of format
    components, since other parts of the compiler may also need it
    in the future.

    Fix two occurrences of a bug that is totally unrelated to the above:
    list_to_pieces and strict_list_to_pieces treated the last element
    in their input list differently from all the other elements.

compiler/parse_tree_out_term.m:
    Add a utility function for use by new code in error_util.m.

compiler/typecheck_errors.m:
    Conform to the new argument order of type_to_pieces.

tests/invalid/actual_expected.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/ext_type.err_exp:
tests/invalid/ext_type_bug.err_exp:
tests/invalid/foreign_procs_exist_type.err_exp:
tests/invalid/higher_order_mode_mismatch.err_exp:
tests/invalid/ho_type_arity_bug.err_exp:
tests/invalid/no_method.err_exp:
tests/invalid/nullary_ho_func_error.err_exp:
tests/invalid/overloading.err_exp:
tests/invalid/type_error_ambiguous.err_exp:
tests/invalid/type_mismatch.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/user_field_access_decl_override2.err_exp:
tests/invalid_purity/impure_func_t5.err_exp:
tests/invalid_purity/impure_pred_t1.err_exp:
tests/invalid_purity/impure_pred_t1_fixed.err_exp:
tests/invalid_purity/impure_pred_t2.err_exp:
    Expect types in error messages in their updated format.
2022-02-21 17:56:52 +11:00

12 lines
615 B
Plaintext

no_method.m:035: In clause for type class method implementation:
no_method.m:035: error: wrong number of arguments (3; should be 2) in use of
no_method.m:035: constructor `one_str'.
no_method.m:043: In clause for type class method implementation:
no_method.m:043: type error in unification of variable `HeadVar__4'
no_method.m:043: and functor `three_str'/3.
no_method.m:043: variable `HeadVar__4' has type
no_method.m:043: string,
no_method.m:043: functor `three_str'/3 has type
no_method.m:043: three_str(string, string, string): func(int) = string.
For more information, recompile with `-E'.