Improve two rarely-seen diagnostics.

compiler/parse_type_defn.m:
    As above.

tests/invalid/field_syntax_error.{m,err_exp}:
tests/invalid/types.{m,err_exp}:
    Add an instance of each bug the diagnostics are for,
    and test for the updated diagnostic text.
This commit is contained in:
Zoltan Somogyi
2026-02-15 23:45:25 +11:00
parent f51eb26a44
commit 8597feaae6
5 changed files with 18 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
% vim: ft=mercury ts=4 sw=4 et % vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------e %-----------------------------------------------------------------------------e
% Copyright (C) 2008-2011 The University of Melbourne. % Copyright (C) 2008-2011 The University of Melbourne.
% Copyright (C) 2016-2025 The Mercury team. % Copyright (C) 2016-2026 The Mercury team.
% This file may only be copied under the terms of the GNU General % This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution. % Public License - see the file COPYING in the Mercury distribution.
%---------------------------------------------------------------------------% %---------------------------------------------------------------------------%
@@ -525,9 +525,12 @@ convert_constructor_arg_list(ModuleName, VarSet, [Term | Terms])
MaybeSymNameAndArgs = ok2(SymName, SymNameArgs), MaybeSymNameAndArgs = ok2(SymName, SymNameArgs),
( (
SymNameArgs = [_ | _], SymNameArgs = [_ | _],
% XXX Should we add "... at function symbol ..."? NameTermStr = describe_error_term(VarSet, NameTerm),
Pieces = [words("Error: syntax error in constructor name."), Pieces = [words("Error: expected a")] ++
nl], color_as_correct([words("simple identifier")]) ++
[words("as the field name, got")] ++
color_as_incorrect([words(NameTermStr), suffix(".")]) ++
[nl],
Spec = spec($pred, severity_error, phase_t2pt, Spec = spec($pred, severity_error, phase_t2pt,
get_term_context(Term), Pieces), get_term_context(Term), Pieces),
MaybeConstructorArgs = error1([Spec]) MaybeConstructorArgs = error1([Spec])
@@ -906,8 +909,8 @@ parse_eqv_type_defn(ModuleName, VarSet, HeadTerm, BodyTerm, Context, SeqNum,
cord.from_list([words("On the left hand side of type definition:")]), cord.from_list([words("On the left hand side of type definition:")]),
parse_type_defn_head(HeadContextPieces, ModuleName, VarSet, HeadTerm, parse_type_defn_head(HeadContextPieces, ModuleName, VarSet, HeadTerm,
MaybeNameAndParams), MaybeNameAndParams),
% XXX Should pass more correct BodyContextPieces. BodyContextPieces = cord.from_list(
BodyContextPieces = cord.init, [words("On the right hand side of equivalence type definition:")]),
parse_type(allow_ho_inst_info, VarSet, BodyContextPieces, BodyTerm, parse_type(allow_ho_inst_info, VarSet, BodyContextPieces, BodyTerm,
MaybeType), MaybeType),
( if ( if

View File

@@ -45,4 +45,6 @@ field_syntax_error.m:034: probably typed `=' where you meant to typ
field_syntax_error.m:034: Warning: if the expression `!Foo ^ f2' is intended to field_syntax_error.m:034: Warning: if the expression `!Foo ^ f2' is intended to
field_syntax_error.m:034: be part of a field update, then it should be field_syntax_error.m:034: be part of a field update, then it should be
field_syntax_error.m:034: followed by `:=', not `='. field_syntax_error.m:034: followed by `:=', not `='.
field_syntax_error.m:037: Error: expected a simple identifier as the field
field_syntax_error.m:037: name, got f(N).
For more information, recompile with `-E'. For more information, recompile with `-E'.

View File

@@ -32,3 +32,6 @@ baz4(Foo) = Foo^44:=45.
baz5(!.Foo) = !:Foo :- baz5(!.Foo) = !:Foo :-
!Foo ^ f1 := 42, !Foo ^ f1 := 42,
!Foo ^ f2 = 43. !Foo ^ f2 = 43.
:- type bar
---> bar(f(N) :: int).

View File

@@ -44,3 +44,5 @@ types.m:063: declaration for module `string'.
types.m:072: In clause for predicate `repeated_arity'/3: types.m:072: In clause for predicate `repeated_arity'/3:
types.m:072: error: wrong number of arguments (2; should be 3) types.m:072: error: wrong number of arguments (2; should be 3)
types.m:072: in call to predicate `append'. types.m:072: in call to predicate `append'.
types.m:080: On the right hand side of equivalence type definition: error: `5'
types.m:080: is not a type.

View File

@@ -76,3 +76,5 @@ repeated_arity(A, B, C) :-
append(A, B, C) :- append(A, B, C) :-
C = A + B. C = A + B.
:- type nonsense == 5.