Commit Graph

4 Commits

Author SHA1 Message Date
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
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
Julien Fischer
8b73df26ee Allow repeated type variables in type class instance heads.
The Mercury compiler has long required that all of the type variables referred
to in type class instance head be distinct.  There is no particularly good
reason for this restriction -- the implication that it helps to ensure that
there are no overlapping instances in the reference manual is misleading, since
the way that we do that (at least in the C grades), by using the names of the
base_typeclass_infos, is not affected by type variables.

The major implementation detail needed to support repeated type variables in
instance declarations is that when doing context reduction, we must do full
matching of instances against constraints (i.e. we need to keep track of the
type variable bindings).  Since we already do this, the only change required to
support repeated type variables is to remove the error checking that prevents
it.

compiler/check_typeclass.m:
	Do not require that type variables in instance heads be distinct.

doc/reference_manual.texi:
	Document that repeated type variables are now allowed in instance
	heads.

NEWS:
	Announce the change.

tests/invalid/instance_dup_var.m:
	Shift this test into the valid directory.

tests/invalid/repeated_instance_vars_unsat.{m,err_exp}:
     Check that we get an error if a repeated type variable is bound
     to different types.

tests/valid/Mmakefile:
tests/invalid/Mmakefile:
	Conform to the above changes.

tests/invalid/invalid_instance_declarations.err_exp:
tests/invalid/invalid_instance_declarations.m:
	Remove instances that are now valid.
2013-07-09 15:43:48 +10: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