mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 04:43:53 +00:00
Allow the same field name to be used in different types in the same
module. The main motivation is that when defining a subtype it often
makes sense to use the same field names as in the base/super type,
rather than trying to invent unique field names.
compiler/add_type.m:
Check for duplicate field names within a type only,
not across the module.
compiler/check_parse_tree_type_defns.m:
Only report duplicate field names within the same type.
compiler/typecheck.m:
Make user-supplied declarations for field access functions only
override automatically generated declarations for the same type
constructor, e.g. a user declaration ':- func foo ^ f1 = int'
should not affect 'X ^ f1' for X of type 'bar'.
doc/reference_manual.texi:
Allow duplicate field names in a module, but not within a type.
Describe how user-supplied declarations interact with duplicate
field names.
NEWS:
Announce change.
tests/invalid/repeated_field_name.err_exp:
Update expected error messages.
tests/invalid/Mmakefile:
tests/invalid/user_field_access_decl_conflict.err_exp:
tests/invalid/user_field_access_decl_conflict.m:
tests/invalid/user_field_access_decl_override.err_exp:
tests/invalid/user_field_access_decl_override.m:
tests/invalid/user_field_access_decl_override2.err_exp:
tests/invalid/user_field_access_decl_override2.m:
Add test cases.
27 lines
495 B
Mathematica
27 lines
495 B
Mathematica
% vim: ts=4 sw=4 ft=mercury
|
|
|
|
:- module user_field_access_decl_conflict.
|
|
|
|
:- interface.
|
|
|
|
:- type foo
|
|
---> foo(
|
|
f0 :: int,
|
|
f1 :: int
|
|
).
|
|
|
|
:- type bar
|
|
---> bar(
|
|
f1 :: uint,
|
|
f2 :: int
|
|
).
|
|
|
|
:- func foo ^ f0 = int.
|
|
:- func (foo ^ f0 := int) = foo.
|
|
|
|
:- func foo ^ f1 = int.
|
|
:- func bar ^ f1 = uint. % conflict
|
|
|
|
:- func (foo ^ f1 := int) = foo.
|
|
:- func (bar ^ f1 := uint) = bar. % conflict
|