mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-29 00:04:55 +00:00
We have traditionally allowed type definitions like this
:- type int(A, B, C)
---> f1(A)
; f2(B)
; f3(C).
even though "int" is a type name that is built into Mercury, just with
a different arity.
This diff reserves those type names, generating errors for any attempts
to define them in user code.
compiler/prog_io_util.m:
We used to parse types by trying to match the input term against
one pattern after another. If one pattern didn't match, for any reason,
we went on to the next, the final being to assume that the term's top
functor is the name of a user defined type. This happened even if
the top functor was the name of a builtin type or a word (such as "pred"
that constructed types), but it either had the wrong number of arguments,
or one of the arguments itself had a problem. This lead to a confusing
error message being generated.
We now effectively look at the top functor of the term, and if it is
the name of a builtin inst or mode construct, then we parse it as that
construct requires, and never fall back to interpreting it as a user
defined inst. (To get even better diagnostics, we will need to convert
some utility predicates from indicating the failure of parsing by
failing to indicating it by returning a list of error_specs.)
compiler/prog_io_type_defn.m:
Enforce the prohibition against defining builtin type names,
even with different module qualifiers and/or arities.
Changes the predicates that parse the different kinds of type definitions
to not stop at the first errors they encounter, but to print all
the errors they can find.
When a type parameter of a type definition is repeated, include its name
in the error message.
Delete some out-of-date comments.
compiler/prog_io_mode_defn.m:
When an inst parameter of an inst or mode definition is repeated,
include its name in the error message.
library/bag.m:
Add a predicate that returns only the repeated items in a bag.
doc/reference_manual.texi:
Document the list of reserved inst names.
We could document the list of reserved mode names, but probably
no-one would want to define those anyway, so the list would probably
be more confusing than helpful.
tests/invalid/reserved.{m,err_exp}:
Expect an error message for the attempted redefinition of a builtin type.
Add a valid type as well, and use that to test the error messages
for bad inst definitions. This changes the line numbers; expect the new
line numbers.
tests/invalid/bigtest.err_exp:
tests/invalid/uu_type.err_exp:
Expect an error message for the attempted redefinition of a builtin type.
tests/invalid/errors.err_exp:
Expect a more precise error message.
44 lines
2.6 KiB
Plaintext
44 lines
2.6 KiB
Plaintext
errors.m:012: Error: module must start with a `:- module' declaration.
|
|
errors.m:012: Error: module `errors' should start with either an `:- interface'
|
|
errors.m:012: or an `:- implementation' declaration.
|
|
errors.m:012: The following assumes that the missing declaration is an
|
|
errors.m:012: `:- implementation' declaration.
|
|
errors.m:012: Warning: interface for module `errors' does not export anything.
|
|
errors.m:012: Warning: module `int' is imported using both `:- import_module'
|
|
errors.m:012: and `:- use_module' declarations.
|
|
errors.m:030: Error: `:- mode' declaration for predicate
|
|
errors.m:030: `errors.mode_declaration_without_pred_declaration'/0
|
|
errors.m:030: without corresponding `:- pred' declaration.
|
|
errors.m:034: Error: `:- mode' declaration for predicate
|
|
errors.m:034: `errors.missing_pred_declaration'/0
|
|
errors.m:034: without corresponding `:- pred' declaration.
|
|
errors.m:040: Error: clause for predicate
|
|
errors.m:040: `errors.clause_without_pred_or_mode_declaration'/0
|
|
errors.m:040: without corresponding `:- pred' declaration.
|
|
errors.m:051: Error: constructor `errors.a/0' for type
|
|
errors.m:051: `errors.type_with_multiply_defined_ctors/0' multiply defined.
|
|
errors.m:051: Error: constructor `errors.f/1' for type
|
|
errors.m:051: `errors.type_with_multiply_defined_ctors/0' multiply defined.
|
|
errors.m:053: In the first argument of function symbol `f' of the type
|
|
errors.m:053: `errors.du_type_which_references_undefined_type'/0:
|
|
errors.m:053: error: undefined type `undefined_type'/0.
|
|
errors.m:055: In definition of type
|
|
errors.m:055: `errors.eqv_type_which_references_undefined_type'/0:
|
|
errors.m:055: error: undefined type `undefined_type'/0.
|
|
errors.m:057: Error: circular equivalence type `errors.circular_eqv_type'/0.
|
|
errors.m:059: Error: circular equivalence type
|
|
errors.m:059: `errors.indirectly_circular_eqv_type_1'/0.
|
|
errors.m:060: Error: circular equivalence type
|
|
errors.m:060: `errors.indirectly_circular_eqv_type_2'/0.
|
|
errors.m:062: Error: free type parameter T in RHS of type definition.
|
|
errors.m:063: Error: the type variable T occurs only in the RHS of this type
|
|
errors.m:063: definition.
|
|
errors.m:077: In clause for predicate
|
|
errors.m:077: `errors.pred_with_unresolved_polymorphism'/0:
|
|
errors.m:077: warning: variable `Arg' occurs only once in this scope.
|
|
errors.m:092: In clause for predicate `errors.pred_with_singleton_vars'/1:
|
|
errors.m:092: warning: variable `X' occurs only once in this scope.
|
|
errors.m:101: In definition of type `errors.needs_qualification'/0:
|
|
errors.m:101: error: undefined type `state'/0.
|
|
For more information, recompile with `-E'.
|