Commit Graph

3 Commits

Author SHA1 Message Date
Zoltan Somogyi
f1745bba2d Systematize error reporting in check_typeclass.m.
compiler/check_typeclass.m:
    As above. This makes future changes to the main code of the module easier.
    In some cases, this required carving error message generating code
    out of larger predicates.

    Some errors were being generated by functions that returned an error_spec,
    and others by predicates that added the new error_spec to !Specs.
    Standardize on the latter scheme.

    Use some recently-added auxiliary functions to generate parts of some
    error messages, to present the same info the same way in different
    error messages. This part of the diff causes the changes to .err_exp files
    below.

    Start the name of all the predicates that generate error with "report_".

    Return !:Specs. Do not take an an initial !.Specs argument, because
    any error_specs in it would screw up a test. Our caller always passed us
    [] anyway.

    The non-error-reporting code in this module is (currently) divided into
    six passes. The code that checks for cycles between typeclasses is the
    third pass, but its code was after the code of the fourth pass; fix that.

    Turn some functions into predicates to allow the use of state variables.

    Rename a function symbol to avoid an ambiguity.

    Fix comment rot.

compiler/mercury_compile_front_end.m:
    Don't pass [] as the initial !.Specs.

compiler/hlds_class.m:
    Move a type definition to its proper place.

tests/invalid/bad_instance2.err_exp:
tests/invalid/constraint_proof_bug_lib.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
    Expect updated error messages.
2022-11-24 10:05:06 +11:00
Zoltan Somogyi
748a22a882 Improve diagnostics for bad instance declarations.
compiler/check_typeclass.m:
    When a type in an instance declaration is not a type constructor,
    don't just say what it is; say also what it should be.

    When a type in an instance declaration is a type constructor but some
    of its arguments are not type variables, don't just say so: say *which*
    of their arguments are the problem.

    Do not use "argument" to refer to both "the arguments of the instance
    declaration" and the "arguments of a type constructor"; use the terminology
    "instance type" for the former.

    Always end the line after the ":" in the error's top level description.

    Omit the module qualification of the typeclass name in error messages,
    since the base name of the typeclass, and the context, should always
    be enough to eliminate any ambiguity.

    Fix a bug in the use of choose_number.

    Don't gather the set of seen types, since it was never used.

tests/invalid/invalid_instance_declarations.m:
    Extend this test to type classes with more than one type.

tests/invalid/bad_instance2.err_exp:
tests/invalid/constraint_proof_bug_lib.err_exp:
tests/invalid/fundeps_coverage.err_exp:
tests/invalid/instance_var_bug.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/range_restrict.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/invalid/typeclass_bogus_method.err_exp:
tests/invalid/typeclass_missing_mode_2.err_exp:
tests/invalid/typeclass_test_10.err_exp:
tests/invalid/typeclass_test_3.err_exp:
tests/invalid/typeclass_test_4.err_exp:
tests/invalid/typeclass_test_5.err_exp:
tests/invalid/typeclass_test_9.err_exp:
    Update these expected outputs to account for the changes above.
2018-06-27 19:57:03 +02:00
Zoltan Somogyi
0821b301f2 Require that types/insts/modes in interfaces be defined in the interface.
compiler/module_qual.m:
    The interface of a module A contains items (e.g. predicate declarations)
    that refer to entities such as types, insts, modes etc. They may refer
    to those entities if (a) they are defined in the interface of module A,
    (b) in a parent module of module A, or (c) if they are imported from
    another module, module B, which is imported into module A in the interface
    of module A.

    The old algorithm that attempted to enforce this requirement had a basic
    design fault: it based the decision as to whether the use of an entity
    in the interface was legal solely on the name of the module that defined
    that entity. This correctly implements tests (b) and (c), but it does
    not even attempt to implement the interface test part of (a).
    It therefore allowed exported items to refer to nonexported entities.

    This diff changes the whole design approach to the test. Instead of
    keeping a list of modules *all* of whose entities may be used in the
    interface of the current module, record for *every* entity whether
    it may be used in the interface. Set the permissions differently
    in the interface and implementation sections of the current module.

    Improve the formatting of the ambiguity error message.

NEWS:
    Announce the stricter enforcement of the documented language rules,
    in a new section for potentially compatibility-breaking changes.

compiler/check_typeclass.m:
    Delete a test for a special case of the situation that module_qual.m
    now tests for. If this problem occurs, module_qual.m will pick it up,
    and check_typeclass.m will never even be invoked, so this copy of the test
    can never succeed.

library/hash_table.m:
    Fix code that violated the language rules: we export a type that
    includes another type, but didn't export the second type. We now do.

browser/declarative_analyser.m:
browser/declarative_edt.m:
compiler/coverage_profiling.m:
    Fix code that violated the language rules. We used to export predicates
    and functions whose argument types included nonexported types. As it
    happens, none of those predicates and functions actually need to be
    exported, so keep them private.

    In coverage_profiling.m, don't abstract export a type that is not
    used outside the module, and give a function a name that doesn't
    clash with a type name.

tests/invalid/bug17.{m,err_exp}:
    A new test case to test the error message we get if the module interface
    refers to a nonexported type.

tests/invalid/bad_instance.err_exp:
    This test case used to get two kinds of errors, one of which was
    the illegal use of nonexported type in an exported abstract instance
    declaration. We now discover this error earlier, and stop after we
    do so. Update the expected error message.

tests/invalid/bad_instance2.{m,err_exp}:
    New test case: a modified copy of bad_instance.m, testing the other
    kind of error originally tested by bad_instance.m.

tests/invalid/instance_no_type.err_exp:
    Update the expected error message.

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

tests/benchmarks/query.m:
tests/hard_coded/unused_float_box_test.m:
tests/valid/bug300.m:
tests/valid/deforest_bug.m:
tests/valid/higher_order4.m:
tests/valid/lambda_recompute.m:
tests/valid/mert.m:
tests/valid/reuse_static.m:
tests/valid/switch_detection_bug2.m:
tests/valid/time_yaowl.m:
tests/warnings/unused_args_test.m:
    Fix code that violated the language rules, typically by exporting
    the type that previously, we illegally used in the module interface.

tests/recompilation/add_type_re.err_exp.2:
    Expect the updated ambiguity error message.
2015-11-11 14:28:57 +11:00