mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 20:03:44 +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.
30 lines
576 B
Mathematica
30 lines
576 B
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module reserved.
|
|
|
|
:- interface.
|
|
|
|
:- type int(A, B, C)
|
|
---> f1(A)
|
|
; f2(B)
|
|
; f3(C).
|
|
|
|
:- type t(A, B, C)
|
|
---> g1(A)
|
|
; g2(B)
|
|
; g3(C).
|
|
|
|
:- inst unique(A, B, C)
|
|
---> f1(A)
|
|
; f2(B)
|
|
; f3(C).
|
|
|
|
:- inst u(A, B, C)
|
|
---> g1(A)
|
|
; g2(B)
|
|
; g3(C).
|
|
|
|
:- mode is(A, B, C) == (free >> u(A, B, C)).
|