Commit Graph

8 Commits

Author SHA1 Message Date
Zoltan Somogyi
52c0c52cfd Fix formatting when reporting problem insts.
compiler/error_msg_inst.m:
    Fix a bug that caused the suffix that all paths in two predicates
    were supposed to add at the logical end of the constructed pieces
    (though it could be followed by some punctuation) to *not* be added
    to the constructed pieces on some paths. Since with our current approach,
    the suffix for one inst in a list of insts can be the description
    of *all the insts following it in the list*, this bug could delete
    not just punctuation, but entire insts from the output. This did actually
    happen for the invalid/html text case below.

    Fix a problem that could cause each inst in a list of insts
    to be indented one more level than the previous inst, which can be
    very confusing.

    Delete the comma from "instname, which expands to ...". When this output
    occurs in an argument list, the presence of the comma can make it
    harder to recognize where one argument ends and the next argument begins.

    Factor out some common code.

    Add an XXX noting a problem.

    Fix documentation.

compiler/parse_tree_out_inst.m:
    Provide two functions for use by error_msg_inst.m.

compiler/prog_mode.m:
    Fix a comment.

tests/invalid/html.m:
    Fix the description of the problem we are testing for.

tests/invalid/html.err_exp:
    Expect the fix for the "omitted insts" bug above.

tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
    Do not expect the deleted comma.
2022-02-05 19:40:51 +11:00
Zoltan Somogyi
3dc4babb24 Update the style of more test cases.
And update expected output files for changes in line numbers.
2021-07-27 13:29:46 +10:00
Zoltan Somogyi
ffa87fc0d9 Update the programming style of some tests in invalid.
tests/invalid/bug10.{m,err_exp}:
tests/invalid/bug115.{m,err_exp}:
tests/invalid/bug117.{m,err_exp}:
tests/invalid/bug191.{m,err_exp}:
tests/invalid/bug436.{m,err_exp}:
tests/invalid/invalid_binary_literal.{m,err_exp}:
tests/invalid/invalid_decimal_literal.{m,err_exp}:
tests/invalid/invalid_float_literal.{m,err_exp}:
tests/invalid/invalid_hex_literal.{m,err_exp}:
tests/invalid/invalid_octal_literal.{m,err_exp}:
tests/invalid/invalid_pragma.{m,err_exp}:
tests/invalid/require_tailrec_invalid.{m,err_exp}:
tests/invalid/type_lhs_var.{m,err_exp}:
tests/invalid/typeclass_no_param.{m,err_exp}:
tests/invalid/unrecognized_pragma.{m,err_exp}:
    Put vim modelines into these .m files, and improve their
    programming style.

    Update the .err_exp files for the changed line numbers.
2019-07-25 21:42:21 +02:00
Zoltan Somogyi
d64966713c Fix an infinite loop when prettyprinting insts for error messages.
compiler/error_msg_inst.m:
    When prettyprinting insts for use in error messages, we have to be careful
    to generate finite output even for recursive insts. Previously, we did
    the required check when processing user-defined inst names, but not when
    processing compiler-generated inst names, which can also be recursive.
    Fix this bug, which is Mantis bug 415.

    Previously, we passed information about what potentially-recursive inst
    names we have seen so far only downward. With the fix above, this avoids
    infinite loops, but in some cases, it leads us to print the definition
    of a given named inst more than once. Change our approach so that we
    now pass information about the set of potentially-recursive inst names
    we have seen sideways as well. This can make us generate more compact
    and therefore more understandable output when prettyprinting insts that
    contain such non-nested duplication.

    When printing something that says "inst name x, which expands to ...",
    indent the "..." one level deeper than the "inst name x". This visually
    separates the thing being defined and its definition.

    When prettyprinting complex insts, we show their structure using
    indentation levels in the output. Each increase of indentation
    should be balanced by a later matching decrease. Move the code that
    does the increase and the decrease next to each other, to make it easier
    to see the implicit correctness argument.

tests/invalid/bug415.{m,err_exp}:
    A new test case for this bug.

tests/invalid/Mmakefile:
    Enable the new test case.

tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
    Expect the extra level of indentation after "which expands to".

tests/invalid/ho_default_func_4.err_exp:
    Expect the extra level of indentation after "which expands to",
    and expect a repeated inst name NOT to have its definition repeated.
2016-08-30 18:37:19 +10:00
Zoltan Somogyi
f4ad6de055 Generate more readable mode errors.
compiler/mode_errors.m:
    When printing insts in error messages, use predicates specifically
    designed for that purpose.

    The insts output by these predicates improve on the existing output
    in the following ways.

    - We now show the structure of complex insts through indentation.

    - We now show both the name of named insts, and their expansion.
      Sometimes, you need the expanded inst to understand the error message,
      in the case of recursive insts, you cannot expand them forever.
      Since the expansion *has* to refer to the inst name, showing that name
      at the *start* of the expansion is necessary to allow readers to
      understand the inst.

    - We now eliminate the module qualification from the names of function
      symbols. The module qualifiers on function symbols are specified
      by the type, not the inst, of the relevant term, and if we get to
      the point of mode analysis having been run, then the predicate
      we are generating errors for must be *type* correct, though obviously
      it is not *mode* correct.

    - We now eliminate the module qualification from names of named insts
      if the module qualifier is the name of the module being compiled.
      This is a common case, and in these cases, the module qualifier
      in the error message acts as clutter, making it *harder* to read.

    - We now avoid printing parentheses that humans never need, but which
      the parser sometimes does, and which the existing inst output predicates
      therefore had to print.

    - Higher order insts contain the modes of the function or predicate.
      We now print the builtin modes as e.g. "in" instead of the old
      "free >> ground".

compiler/error_util.m:
    Add some utility predicates now needed by mode_errors.m.

tests/invalid/any_passed_as_ground.err_exp2:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.sub.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/state_vars_test4.err_exp:
tests/invalid/try_detism.err_exp2:
tests/warnings/unify_f_g.exp:
    Update expected outputs.
2015-11-29 04:33:41 +11:00
Julien Fischer
5d9af535c5 Improve message for mode errors in type class method implementations.
compiler/mode_errors.m:
    Don't refer to method wrapper predicates by their internal names
    (i.e. 'ClassMethod_for_ ...) in mode errors.  Instead report the
    method name and identify it as a type class method implementation.

compiler/hlds_error_util.m:
    Don't hardcode the quoting style in a spot.

tests/invalid/bug191.err_exp:
    Conform to the changed error message.
2015-11-13 13:41:16 +11:00
Julien Fischer
f45a1a8967 Report an error for a type class with no parameters.
The compiler was not rejecting typeclass declarations without any class
parameters, for example:

    :- typeclass foo where [].

Mercury requires typeclass declarations to have at least one class parameter.

compiler/prog_io_typeclass.m:
    Emit an error if we encounter a typeclass declaration with no parameters.

tests/invalid/Mmakefile:
tests/invalid/typeclass_no_param.{m,err_exp:
    Add a regression test for the above.

tests/invalid/bug191.{m,err_exp}:
    Avoid having a typeclass with no parameters.
2015-11-04 20:12:11 +11:00
Julien Fischer
921d154488 Add a regression test for bug #191.
tests/invalid/Mmakefile:
tests/invalid/bug191.{m,err_exp}:
    As above.
2015-11-02 11:19:49 +11:00