Do not allow non-abstract instance declarations to occur in module

For review by anyone.

Estimated hours taken: 10
Branches: main, release

Do not allow non-abstract instance declarations to occur in module
interfaces.  Emit an error message if this occurs.

Fix the formatting of some error messages regarding typeclasses
and instances.

compiler/check_typeclass.m:
	Use error_util to generate the error messages from this module.
	This fixes a problem where the printing of sym_names and arities
	differed in the same error message.

compiler/error_util.m:
	Add a format component for the pred_or_func type.
	Add the equivalence type format_components.

compiler/make_hlds.m:
	Make the format of some error messages concerning typeclasses
	more consistent.

compiler/modules.m:
	Check for non-abstract instance declarations in module interfaces
	and emit an error message if they do.

tests/invalid/Mmakefile:
tests/invalid/instance_bug.m:
tests/invalid/instance_bug.err_exp:
 	Test case for the above.

tests/hard_coded/typeclasses/*:
tests/invalid/*:
tests/recompilation/*:
tests/valid/*:
	Update test cases as necessary.
This commit is contained in:
Julien Fischer
2005-04-12 07:58:24 +00:00
parent 8470885fe0
commit a0e5667af5
66 changed files with 484 additions and 338 deletions

View File

@@ -67,9 +67,15 @@
% The output should contain the string form of
% the sym_name, followed by '/' and the arity,
% all surrounded by `' quotes.
; nl. % Insert a line break if there has been text
; nl % Insert a line break if there has been text
% output since the last line break.
; pred_or_func(pred_or_func).
% Output the string "predicate" or "function"
% as appropriate.
:- type format_components == list(format_component).
% Convert a list of strings into a list of format_components
% separated by commas, with the last two elements separated by `and'.
@@ -128,6 +134,7 @@
% Append a punctuation character to a message, avoiding unwanted
% line splitting between the message and the punctuation.
%
:- func append_punctuation(list(format_component), char) =
list(format_component).
@@ -374,6 +381,9 @@ error_pieces_to_string([Component | Components]) = Str :-
;
Str = Word ++ " " ++ TailStr
)
;
Component = pred_or_func(PredOrFunc),
Str = pred_or_func_to_string(PredOrFunc)
;
Component = nl,
Str = "\n" ++ TailStr
@@ -389,39 +399,37 @@ error_pieces_to_string([Component | Components]) = Str :-
list(word)::in, list(list(string))::in, list(list(string))::out)
is det.
convert_components_to_word_list([], RevWords0, Paras0, Paras) :-
convert_components_to_word_list([], RevWords0, !Paras) :-
Strings = rev_words_to_strings(RevWords0),
list__reverse([Strings | Paras0], Paras).
convert_components_to_word_list([Component | Components], RevWords0,
Paras0, Paras) :-
list__reverse([Strings | !.Paras], !:Paras).
convert_components_to_word_list([Component | Components], RevWords0, !Paras) :-
(
Component = fixed(Word),
RevWords1 = [word(Word) | RevWords0],
Paras1 = Paras0
RevWords1 = [word(Word) | RevWords0]
;
Component = suffix(Word),
RevWords1 = [suffix_word(Word) | RevWords0],
Paras1 = Paras0
RevWords1 = [suffix_word(Word) | RevWords0]
;
Component = words(WordsStr),
break_into_words(WordsStr, RevWords0, RevWords1),
Paras1 = Paras0
break_into_words(WordsStr, RevWords0, RevWords1)
;
Component = sym_name(SymName),
RevWords1 = [word(sym_name_to_word(SymName)) | RevWords0],
Paras1 = Paras0
RevWords1 = [word(sym_name_to_word(SymName)) | RevWords0]
;
Component = sym_name_and_arity(SymNameAndArity),
Word = sym_name_and_arity_to_word(SymNameAndArity),
RevWords1 = [word(Word) | RevWords0],
Paras1 = Paras0
RevWords1 = [word(Word) | RevWords0]
;
Component = pred_or_func(PredOrFunc),
Word = pred_or_func_to_string(PredOrFunc),
RevWords1 = [word(Word) | RevWords0]
;
Component = nl,
Strings = rev_words_to_strings(RevWords0),
Paras1 = [Strings | Paras0],
list.cons(Strings, !Paras),
RevWords1 = []
),
convert_components_to_word_list(Components, RevWords1, Paras1, Paras).
convert_components_to_word_list(Components, RevWords1, !Paras).
:- func rev_words_to_strings(list(word)) = list(string).
@@ -618,6 +626,10 @@ append_punctuation([Piece0], Punc) = [Piece] :-
Piece0 = sym_name_and_arity(SymNameAndArity),
String = sym_name_and_arity_to_word(SymNameAndArity),
Piece = fixed(string__append(String, char_to_string(Punc)))
;
Piece0 = pred_or_func(PredOrFunc),
String = pred_or_func_to_string(PredOrFunc),
Piece = fixed(string__append(String, char_to_string(Punc)))
;
Piece0 = nl,
error("append_punctutation: " ++