mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 03:13:40 +00:00
Before this diff, typecheck_error.m could generate error messages like this:
a02x.m:020: In clause for predicate `p1'/3:
a02x.m:020: in argument 1 of call to predicate `foldl'/4:
a02x.m:020: type error: type of argument does not match its expected type;
a02x.m:020: argument has overloaded actual/expected types {
a02x.m:020: (expected) pred(L, A, A),
a02x.m:020: (expected) pred(character, A, A),
a02x.m:020: (inferred) pred(int, a02x.dir, int),
a02x.m:020: (inferred) pred(int, a02x.dir, int)
As evidenced by a post on m-users, this can be confusing, because the message
says nothing about where the expected types came from.
This diff changes the way we generate error message for errors in which
there is one actual inferred type, but two or more expected types.
It changes the output in two ways:
- it identifies the sources of the expected types, and
- it prints the inferred type just once.
The message we generate for the same code is now
a02x.m:020: In clause for predicate `p1'/3:
a02x.m:020: in argument 1 of call to predicate `foldl'/4:
a02x.m:020: type error: type of argument does not match its expected type;
a02x.m:020: its inferred type is
a02x.m:020: pred(int, a02x.dir, int),
a02x.m:020: the type expected by predicate `list.foldl'/4 is:
a02x.m:020: pred(L, A, A),
a02x.m:020: the type expected by predicate `string.foldl'/4 is:
a02x.m:020: pred(character, A, A).
compiler/type_assign.m:
Expand the args_type_assign type to include a source of the expected type.
To make this possible, move the cons_type_info type here from
typecheck_info.m.
In the process, both simplify and expand one of the cons_type_info type's
components, the cons_type_info_source type. Simplify it by replacing
the two sources source_{get}_field_access, which are always treated
near-identically, with just one source, source_field_access, which has
an extra field specifying get vs set. Expand it by specifying two details
we didn't need before: the cons_id if the cons_type_info came from
a data constructor in a type_ctor, and the field name if it came from
a field access function.
Give some fields less misleading names. Update the names of functions
returning these fields accordingly.
compiler/typecheck_info.m:
Delete the code moved to type_assign.m.
compiler/typecheck.m:
Record the sources of args_type_assigns.
Use more consistent variable names.
Fix some misleading predicate names.
Put loop-invarient input arguments before non-loop-invariant arguments.
Fix bit-rot in some comments.
compiler/typecheck_errors.m:
As mentioned above, if there is just one actual (inferred) type,
but two or more expected types, then
- print the inferred type just once, and
- identify the sources of the expected types.
Put the fields of the arg_type_stuff in the same order as our
error message: inferred, then expected.
Add some XXXs.
compiler/post_typecheck.m:
Fix a comment.
tests/invalid/actual_more_expected.{m,err_exp}:
Add this test case, which is derived from the program on m-users.
tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
Enable the new test case, and invoke it with -E.
135 lines
7.7 KiB
Plaintext
135 lines
7.7 KiB
Plaintext
# vim: ts=4 sw=4 expandtab
|
|
#
|
|
# Inter-module optimization changes the diagnostics for some tests
|
|
# (in most cases reporting diagnostics when writing the `.opt' file).
|
|
# For those tests, we just disable inter-module optimization.
|
|
|
|
MCFLAGS-any_mode = --infer-types
|
|
|
|
# XXX This test should work with --intermodule-optimization, but the compiler
|
|
# doesn't know whether items imported from `.opt' files were imported
|
|
# in the interface or the implementation. The error is reported correctly
|
|
# when building the `.opt' file.
|
|
MCFLAGS-assert_in_interface = --no-intermodule-optimization \
|
|
--verbose-error-messages
|
|
|
|
MCFLAGS-abstract_eqv = --no-intermodule-optimization
|
|
MCFLAGS-actual_expected = --no-intermodule-optimization
|
|
MCFLAGS-actual_more_expected = -E
|
|
MCFLAGS-any_to_ground_in_ite_cond_nomax = --no-max-error-line-width
|
|
MCFLAGS-bug214 = --allow-stubs --no-warn-stubs
|
|
# Mantis bug 238 shows up in bug238.m only with --constraint-propagation.
|
|
MCFLAGS-bug238 = --constraint-propagation
|
|
MCFLAGS-children = --no-intermodule-optimization
|
|
MCFLAGS-coerce_implied_mode = --halt-at-warn
|
|
MCFLAGS-coerce_infer = --infer-all
|
|
MCFLAGS-coerce_void = --halt-at-warn
|
|
MCFLAGS-duplicate_instance_2 = --no-intermodule-optimization
|
|
MCFLAGS-ee_invalid = --verbose-error-messages
|
|
MCFLAGS-exported_mode = --infer-all --no-intermodule-optimization
|
|
MCFLAGS-exported_unify = --no-intermodule-optimization
|
|
MCFLAGS-fe_unmapped_verbose = --verbose-error-messages
|
|
MCFLAGS-foreign_decl_line_number = --no-errorcheck-only --line-numbers \
|
|
--line-numbers-for-c-headers
|
|
MCFLAGS-foreign_enum_invalid = --verbose-error-messages
|
|
MCFLAGS-foreign_type_line_number = --no-errorcheck-only --line-numbers \
|
|
--compile-only
|
|
MCFLAGS-foreign_type = --compile-only
|
|
MCFLAGS-foreign_type_2 = --no-intermodule-optimization
|
|
MCFLAGS-foreign_type_visibility = --no-intermodule-optimization
|
|
MCFLAGS-gh72_errors = --no-errorcheck-only
|
|
MCFLAGS-ii_parent = --no-intermodule-optimization
|
|
MCFLAGS-ii_parent.ii_child = --no-intermodule-optimization
|
|
MCFLAGS-illtyped_compare = --no-intermodule-optimization \
|
|
--verbose-error-messages
|
|
MCFLAGS-imported_mode = --infer-all --no-intermodule-optimization
|
|
MCFLAGS-impure_method_impl = --no-intermodule-optimization \
|
|
--verbose-error-messages
|
|
MCFLAGS-inline_conflict = --no-warn-ambiguous-pragmas
|
|
MCFLAGS-invalid_event = --event-set-file-name invalid_event_spec
|
|
MCFLAGS-invalid_mllibs = --no-errorcheck-only --no-verbose-make \
|
|
--options-file Mercury.options.invalid \
|
|
--make invalid_mllibs
|
|
MCFLAGS-instance_var_bug = --verbose-error-messages
|
|
MCFLAGS-loopcheck = --warn-inferred-erroneous \
|
|
--verbose-error-messages
|
|
MCFLAGS-max_error_line_width = --max-error-line-width 120 \
|
|
--verbose-error-messages
|
|
MCFLAGS-method_impl = --no-intermodule-optimization \
|
|
--verbose-error-messages
|
|
MCFLAGS-missing_det_decls = --no-infer-det --verbose-error-messages
|
|
MCFLAGS-missing_interface_import2 = --no-intermodule-optimization
|
|
MCFLAGS-mode_inf = --infer-all --verbose-error-messages
|
|
MCFLAGS-mpj1 = --infer-all --verbose-error-messages
|
|
MCFLAGS-multisoln_func = --infer-types --verbose-error-messages
|
|
MCFLAGS-nonexistent_import = --no-verbose-make --make nonexistent_import
|
|
MCFLAGS-overloading = --no-intermodule-optimization
|
|
MCFLAGS-pragma_c_code_no_det = --warn-inferred-erroneous
|
|
MCFLAGS-record_syntax_errors = --verbose-error-messages
|
|
MCFLAGS-string_format_bad = --halt-at-warn --warn-known-bad-format-calls \
|
|
--warn-unknown-format-calls
|
|
MCFLAGS-string_format_unknown = --halt-at-warn --warn-known-bad-format-calls \
|
|
--warn-unknown-format-calls
|
|
MCFLAGS-subtype_user_compare = --verbose-error-messages
|
|
MCFLAGS-synth_attr_error = --event-set-file-name synth_attr_error_spec
|
|
MCFLAGS-syntax_error_event = --event-set-file-name syntax_error_event_spec
|
|
|
|
# Force this test to be compiled in a non-trailing grade since in this
|
|
# case the error we want to report is the absence of trailing.
|
|
MCFLAGS-trailed_mutable = --no-use-trail
|
|
|
|
MCFLAGS-test_nested = --no-intermodule-optimization \
|
|
--verbose-error-messages
|
|
MCFLAGS-transitive_import = --no-intermodule-optimization
|
|
MCFLAGS-transitive_import2 = --no-intermodule-optimization
|
|
MCFLAGS-transitive_import_class = --no-intermodule-optimization
|
|
MCFLAGS-transitive_import_class2 = --no-intermodule-optimization
|
|
MCFLAGS-transitive_import_class3 = --no-intermodule-optimization
|
|
MCFLAGS-typeclass_mode = --infer-all
|
|
MCFLAGS-undef_symbol = --no-intermodule-optimization
|
|
|
|
# Include the verbose part of the error message where we have one.
|
|
MCFLAGS-ambiguous_method = --verbose-error-messages
|
|
MCFLAGS-anys_in_negated_contexts = --verbose-error-messages
|
|
MCFLAGS-bind_in_negated = --verbose-error-messages
|
|
MCFLAGS-bug83 = --verbose-error-messages
|
|
MCFLAGS-complex_constraint_err = --verbose-error-messages
|
|
MCFLAGS-ext_type = --verbose-error-messages
|
|
MCFLAGS-ext_type_bug = --verbose-error-messages
|
|
MCFLAGS-freefree = --verbose-error-messages
|
|
MCFLAGS-ho_default_func_1 = --verbose-error-messages
|
|
MCFLAGS-ho_default_func_3 = --verbose-error-messages
|
|
MCFLAGS-ho_type_mode_bug = --verbose-error-messages
|
|
MCFLAGS-make_opt_error = --verbose-error-messages
|
|
MCFLAGS-modes_erroneous = --verbose-error-messages
|
|
MCFLAGS-mpj4 = --verbose-error-messages
|
|
MCFLAGS-multimode_syntax = --verbose-error-messages
|
|
MCFLAGS-nullary_ho_func_error = --verbose-error-messages
|
|
MCFLAGS-one_member = --verbose-error-messages
|
|
MCFLAGS-polymorphic_unification = --verbose-error-messages
|
|
|
|
MCFLAGS-require_tailrec_1 = -O0 --optimise-tailcalls \
|
|
--no-warn-non-tail-recursion
|
|
MCFLAGS-require_tailrec_2 = -O0 --optimise-tailcalls \
|
|
--warn-non-tail-recursion self -E
|
|
MCFLAGS-require_tailrec_3 = -O0 --optimise-tailcalls \
|
|
--warn-non-tail-recursion self-and-mutual
|
|
|
|
# We compile test_feature_set in grade java because that grade is incompatible
|
|
# with the features in the test require_feature_set pragma.
|
|
MCFLAGS-test_feature_set = --grade java --verbose-error-messages
|
|
MCFLAGS-tricky_assert1 = --verbose-error-messages
|
|
MCFLAGS-type_error_use_module = --verbose-error-messages \
|
|
--no-intermodule-optimization
|
|
MCFLAGS-typeclass_dup_method_mode = --verbose-error-messages
|
|
MCFLAGS-typeclass_constraint_extra_var = --verbose-error-messages
|
|
MCFLAGS-typeclass_missing_det_3 = --verbose-error-messages
|
|
MCFLAGS-typeclass_test_12 = --verbose-error-messages
|
|
MCFLAGS-typeclass_test_8 = --verbose-error-messages
|
|
MCFLAGS-types2 = --verbose-error-messages \
|
|
--warn-non-contiguous-clauses
|
|
MCFLAGS-type_vars = --verbose-error-messages
|
|
MCFLAGS-undef_type = --verbose-error-messages
|
|
MCFLAGS-unsatisfiable_constraint = --verbose-error-messages
|
|
MCFLAGS-user_eq_dummy = --verbose-error-messages
|