Commit Graph

10 Commits

Author SHA1 Message Date
Zoltan Somogyi
7b82c59c40 Remove unneeded module qualifications from error messages.
This should make error messages easier to read by removing clutter.

compiler/error_util.m:
    Split each of the sym_name and sym_name_and_arity error pieces into two;
    one which prints any module qualification present in the given sym_name,
    and one which does not. This forces people who use these pieces
    to think about whether they want the sym_name module qualified
    in the error message or not.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_enum.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/check_for_missing_type_defns.m:
compiler/check_promise.m:
compiler/check_raw_comp_unit.m:
compiler/check_typeclass.m:
compiler/det_report.m:
compiler/equiv_type.m:
compiler/format_call.m:
compiler/hlds_error_util.m:
compiler/inst_check.m:
compiler/introduce_parallelism.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_tags.m:
compiler/mercury_compile_main.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/module_qual.qual_errors.m:
compiler/modules.m:
compiler/oisu_check.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_pragma.m:
compiler/parse_type_defn.m:
compiler/polymorphism.m:
compiler/post_term_analysis.m:
compiler/prog_out.m:
compiler/recompilation.check.m:
compiler/resolve_unify_functor.m:
compiler/split_parse_tree_src.m:
compiler/type_constraints.m:
compiler/typecheck_errors.m:
compiler/unused_args.m:
compiler/unused_imports.m:
    Conform to the change above. For sym_name references for which
    the module qualifier is obvious (usually because it *has* to be
    the module being compiled), change the reference to the variant
    that omits that qualifier; otherwise, keep the qualifier.

    In a few places, improve the wording of an error message.

tests/invalid/bad_instance.err_exp:
tests/invalid/bug17.err_exp:
tests/invalid/builtin_int.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/foreign_type_visibility.err_exp:
tests/invalid/fp_dup_bug.err_exp:
tests/invalid/fundeps_vars.err_exp:
tests/invalid/impl_def_literal_syntax.err_exp:
tests/invalid/inline_conflict.err_exp:
tests/invalid/inst_list_dup.err_exp:
tests/invalid/instance_no_type.err_exp:
tests/invalid/invalid_typeclass.err_exp:
tests/invalid/missing_interface_import.err_exp:
tests/invalid/missing_interface_import2.err_exp:
tests/invalid/oisu_check_semantic_errors.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/invalid/transitive_import.err_exp:
tests/invalid/type_with_no_defn.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:
tests/invalid/types2.err_exp:
tests/invalid/undef_inst.err_exp:
tests/invalid/undef_mode.err_exp:
tests/invalid/undef_mode_and_no_clauses.err_exp:
tests/invalid/undef_type.err_exp:
tests/invalid/undef_type_mod_qual.err_exp:
tests/invalid/uu_type.err_exp:
tests/invalid/where_direct_arg.err_exp:
tests/invalid/where_direct_arg2.err_exp:
tests/invalid/wrong_type_arity.err_exp:
tests/recompilation/add_type_re.err_exp.2:
tests/recompilation/field_r.err_exp.2:
tests/recompilation/remove_type_re.err_exp.2:
tests/warnings/inst_with_no_type.exp:
    Expect the updated versions of error messages.
2017-04-01 20:20:57 +11: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
Zoltan Somogyi
fdd141bf77 Clean up the tests in the other test directories.
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the tests
    that check compiler error messages, expect the new line numbers.

browser/cterm.m:
browser/tree234_cc.m:
    Import only one module per line.

tests/hard_coded/boyer.m:
    Fix something I missed.
2015-02-16 12:32:18 +11:00
Zoltan Somogyi
06cd3bfc7a Do several kinds of cleanups. There are no algorithmic changes.
Estimated hours taken: 1
Branches: main

compiler/check_typeclasses.m:
	Do several kinds of cleanups. There are no algorithmic changes.

	First, this modules does several different checks. Put the code that
	does those checks in the same order as the comment at the top
	explaining them, and the order in which they are executed.

	Second, give some predicates and variables more meaningful names.

	Third, fix the error messages so that they form complete sentences,
	and do not use abbreviations unnecessarily.

tests/invalid/bad_instance.err_exp:
tests/invalid/instance_dup_var.err_exp:
tests/invalid/instance_var_bug.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/invalid_typeclass.err_exp:
	Conform to the third change above.
2012-06-04 08:35:09 +00:00
Peter Wang
d9e30aec5b Don't write an outer pair of brackets when formatting terms with '.'
Branches: main

compiler/mercury_to_mercury.m:
	Don't write an outer pair of brackets when formatting terms with '.'
	or ':' as the functor, which made module-qualified types in error
	messages unnecessarily ugly.

tests/hard_coded/impl_def_literal.exp:
tests/invalid/actual_expected.err_exp:
tests/invalid/bad_instance.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/ext_type.err_exp:
tests/invalid/ext_type_bug.err_exp:
tests/invalid/funcs_as_preds.err_exp:
tests/invalid/illtyped_compare.err_exp:
tests/invalid/instance_dup_var.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/mixed_up_streams.err_exp:
tests/invalid/mpj4.err_exp:
tests/invalid/nullary_ho_func_error.err_exp:
tests/invalid/overloading.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:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/invalid/try_bad_params.err_exp:
tests/invalid/type_error_ambiguous.err_exp:
tests/misc_tests/pretty_print_test.exp:
tests/warnings/inference_test.exp:
	Update test cases.
2009-04-16 02:09:09 +00:00
Julien Fischer
dc1e59e48b Fix a bug (#27) reported by Ralph. The compiler was aborting on
Estimated hours taken: 1
Branches: main

Fix a bug (#27) reported by Ralph.  The compiler was aborting on
instances that contained type variables that were not wrapped in functors.
The problem is that the name mangling scheme used to mangle the names of
method wrapper predicates cannot handle instances that contain unwrapped
type variables.  The compiler already has code to check for this, but that
check was not being performed until *after* it had attempted to introduce
the method wrapper predicates.

The fix is to reorder the phases of check_typeclass.m so that we perform
the check on the types in an instance first and only run the remaining
phases if the first one succeeds.

compiler/check_typeclass.m:
	Reorder the phases within this module so that we don't attempt
	to introduce method wrapper predicates for invalid instances.

	Update the documentation in this module to conform to the above
	change.

	Remove some unnecessary module qualification.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/invalid/instance_var_bug.{m,err_exp}:
	Test for the above bug.

tests/invalid/bad_instance.err_exp:
	Update this.  The error message for the missing concrete instance
	won't be emitted with the above change.  Note, we have a separate
	test case, tests/invalid/missing_concrete_instance, that exercises
	that error message.
2007-11-14 04:00:06 +00:00
Julien Fischer
8d68293b62 Fix a bug where the compiler failed to emit an error if an exported instance
Estimated hours taken: 2
Branches: main

Fix a bug where the compiler failed to emit an error if an exported instance
declaration contained a type that was only visible in the implementation
of the module.  (This is bug #11 in mantis.)

compiler/check_typeclass.m:
	Check for the above situation and emit an error message.

	Unrelated change: fix the wording of another error message.

	Change some if-then-elses into switches.

compiler/make_hlds_passes.m:
	Break an overlong line.

tests/invalid/Mmakefile:
tests/invalid/instance_no_type.{m,err_exp}:
	Test case for the new error message.

tests/invalid/bad_instance.err_exp:
        Update the exepected output as the new check will cause an
	additional error to be reported for this test.
2007-10-22 05:10:33 +00:00
Peter Ross
010c7faae4 Improve the detection of invalid instance declarations by doing the check
Estimated hours taken: 8
Branches: main

Improve the detection of invalid instance declarations by doing the check
during hlds checking rather than parsing, as we have more information then.

compiler/check_typeclass.m:
	Add check_instance_declaration_types/4, where we check that each type
	the instance declaration must be either a type with no arguments, a
	polymorphic type whose arguments are all distinct type variables.

compiler/error_util.m:
	Add nth_fixed to format_component which returns "first", "second",
	"third", "4th" depending on the given integer.

compiler/prog_io_typeclass.m:
	Remove the invalid instance check during parsing.

compiler/type_util.m:
	Fix a spelling mistake.

tests/hard_coded/typeclasses/fundeps_1.m:
tests/hard_coded/typeclasses/fundeps_2.m:
tests/invalid/ambiguous_method.m:
tests/invalid/ambiguous_method_2.m:
	Fix invalid instance declarations.

tests/invalid/bad_instance.err_exp:
tests/invalid/instance_dup_var.err_exp:
	Update to the new error messages.

tests/invalid/Mmakefile:
tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/invalid_instance_declarations.m:
	Add a check where we use equivalence types to
	hide invalid typeclass declarations.
2007-10-02 04:32:50 +00:00
Julien Fischer
e069d16ab1 Do not display the For more information try recompiling with -E'' prompt
Estimated hours taken: 1.5
Branches: main

Do not display the `For more information try recompiling with `-E'' prompt
unless we really mean it, i.e. there is actually more information available.

XXX This change is incomplete for the mode_errors module because that
module requires more substantial changes to make this work - I'll do
that as a separate diff.

compiler/globals.m
	Add a new global (and access predicates) that keeps track of whether
	we have any verbose error information that could be displayed if we
	recompiled with `-E'.

compiler/mercury_compile.m
	Check the new global flag before prompting the user to recompile with
	`-E'.

compiler/mode_errors.m
	Add an XXX comment about needing to respect the extra error info flag
	properly.

compiler/accumulator.m
compiler/add_clause.m
compiler/add_pred.m
compiler/add_type.m
compiler/assertion.m
compiler/check_typeclass.m
compiler/det_report.m
compiler/magic_util.m
compiler/make_hlds_error.m
compiler/modes.m
compiler/module_qual.m
compiler/modules.m
compiler/post_typecheck.m
compiler/purity.m
compiler/stratify.m
compiler/typecheck_errors.m
	Set the new global flag when we come across an error
	for which we have a verbose error message.

tests/recompilation/*:
tests/invalid/*:
	Update expected error files.
2005-09-14 05:27:11 +00:00
Mark Brown
a8983be041 Report a more useful error if the arguments of an instance are not
Estimated hours taken: 0.2
Branches: main, release

compiler/prog_io_typeclass.m:
	Report a more useful error if the arguments of an instance are not
	in the required form.  The error term is now the entire head of the
	instance, which has a meaningful context.

tests/invalid/Mmakefile:
tests/invalid/bad_instance.err_exp:
tests/invalid/bad_instance.m:
	Test case.
2005-08-03 11:27:00 +00:00