diff --git a/compiler/typecheck_error_overload.m b/compiler/typecheck_error_overload.m index 0d0dbcc70..e6d8fa998 100644 --- a/compiler/typecheck_error_overload.m +++ b/compiler/typecheck_error_overload.m @@ -76,6 +76,7 @@ :- import_module assoc_list. :- import_module map. :- import_module maybe. +:- import_module one_or_more. :- import_module pair. :- import_module require. :- import_module set. @@ -337,51 +338,47 @@ add_qualifiers_reminder = [ describe_overloaded_symbols(ClauseContext, Context, OverloadedSymbolMap) = Msgs :- map.to_assoc_list(OverloadedSymbolMap, OverloadedSymbols), - OverloadedSymbolsSortedContexts = - assoc_list.map_values_only(sort_and_remove_dups, OverloadedSymbols), + assoc_list.map_values_only(sort_and_remove_dups, + OverloadedSymbols, OverloadedSymbolsSortedContexts), ( OverloadedSymbolsSortedContexts = [], Msgs = [] ; ( - OverloadedSymbolsSortedContexts = [_ - Contexts], + OverloadedSymbolsSortedContexts = [_ - OoMContexts], + WasOverloadedPieces = [words("The following symbol was")] ++ + color_as_incorrect([words("overloaded")]), + OoMContexts = one_or_more(_HeadContext, TailContexts), ( - Contexts = [], - unexpected($pred, "no contexts") + TailContexts = [], + FollowingContextPieces = + [words("in the following context."), nl] ; - Contexts = [_], - WasOverloadedPieces = - [words("The following symbol was overloaded"), - words("in the following context."), nl] - ; - Contexts = [_, _ | _], - WasOverloadedPieces = - [words("The following symbol was overloaded"), - words("in the following contexts."), nl] + TailContexts = [_ | _], + FollowingContextPieces = + [words("in the following contexts."), nl] ) ; OverloadedSymbolsSortedContexts = [_, _ | _], - WasOverloadedPieces = - [words("The following symbols were overloaded"), - words("in the following contexts."), nl] + WasOverloadedPieces = [words("The following symbols were")] ++ + color_as_incorrect([words("overloaded")]), + FollowingContextPieces = + [words("in the following contexts."), nl] ), - WasOverloadedMsg = msg(Context, WasOverloadedPieces), + IntroPieces = WasOverloadedPieces ++ FollowingContextPieces, + IntroMsg = msg(Context, IntroPieces), ModuleInfo = ClauseContext ^ tecc_module_info, DetailMsgsList = list.map(describe_overloaded_symbol(ModuleInfo), OverloadedSymbolsSortedContexts), list.condense(DetailMsgsList, DetailMsgs), - Msgs = [WasOverloadedMsg | DetailMsgs] + Msgs = [IntroMsg | DetailMsgs] ). :- func describe_overloaded_symbol(module_info, - pair(overloaded_symbol, list(prog_context))) = list(error_msg). + pair(overloaded_symbol, one_or_more(prog_context))) = list(error_msg). -describe_overloaded_symbol(ModuleInfo, Symbol - SortedContexts) = Msgs :- - ( - SortedContexts = [], - unexpected($pred, "no context") - ; - SortedContexts = [FirstContext | LaterContexts], +describe_overloaded_symbol(ModuleInfo, Symbol - OoMSortedContexts) = Msgs :- + OoMSortedContexts = one_or_more(FirstContext, LaterContexts), % We print a detailed message for the first context, but omit % repeating the list of possible matches for any later contexts. ( @@ -398,9 +395,7 @@ describe_overloaded_symbol(ModuleInfo, Symbol - SortedContexts) = Msgs :- yes(color_hint), should_module_qualify), construct_sorted_line_pieces(MakeItemPiecesFunc, PredIds, PredIdPieces), - FirstPieces = StartPieces ++ PredIdPieces, - LaterPieces = [words("That symbol"), - words("is also overloaded here."), nl] + FirstPieces = StartPieces ++ PredIdPieces ; Symbol = overloaded_func(ConsId, Sources), ConsIdPiece = qual_cons_id_and_maybe_arity(ConsId), @@ -411,14 +406,12 @@ describe_overloaded_symbol(ModuleInfo, Symbol - SortedContexts) = Msgs :- yes(color_hint)), construct_sorted_line_pieces(MakeItemPiecesFunc, Sources, SourcePieces), - FirstPieces = StartPieces ++ SourcePieces, - LaterPieces = [words("That symbol"), - words("is also overloaded here."), nl] + FirstPieces = StartPieces ++ SourcePieces ), + LaterPieces = [words("That symbol is also overloaded here."), nl], FirstMsg = msg(FirstContext, FirstPieces), LaterMsgs = list.map(context_to_error_msg(LaterPieces), LaterContexts), - Msgs = [FirstMsg | LaterMsgs] - ). + Msgs = [FirstMsg | LaterMsgs]. :- func context_to_error_msg(list(format_piece), prog_context) = error_msg. diff --git a/compiler/typecheck_info.m b/compiler/typecheck_info.m index 155647e3b..5fdbb82ae 100644 --- a/compiler/typecheck_info.m +++ b/compiler/typecheck_info.m @@ -57,7 +57,8 @@ % The purpose-specific types of the values held in the typecheck_info. % -:- type overloaded_symbol_map == map(overloaded_symbol, list(prog_context)). +:- type overloaded_symbol_map == + map(overloaded_symbol, one_or_more(prog_context)). :- type overloaded_symbol ---> overloaded_pred( @@ -450,11 +451,11 @@ typecheck_info_get_cons_table(Info, Ctors) :- typecheck_info_add_overloaded_symbol(Symbol, Context, !Info) :- typecheck_info_get_overloaded_symbol_map(!.Info, OverloadedSymbolMap0), ( if map.search(OverloadedSymbolMap0, Symbol, OldContexts) then - Contexts = [Context | OldContexts], + one_or_more.cons(Context, OldContexts, Contexts), map.det_update(Symbol, Contexts, OverloadedSymbolMap0, OverloadedSymbolMap) else - Contexts = [Context], + Contexts = one_or_more(Context, []), map.det_insert(Symbol, Contexts, OverloadedSymbolMap0, OverloadedSymbolMap) ), diff --git a/tests/invalid/ambiguous_overloading_error.err_exp b/tests/invalid/ambiguous_overloading_error.err_exp index 30bcc09ea..dea2a591a 100644 --- a/tests/invalid/ambiguous_overloading_error.err_exp +++ b/tests/invalid/ambiguous_overloading_error.err_exp @@ -5,7 +5,7 @@ ambiguous_overloading_error.m:054: `:- import_module' declaration for module ambiguous_overloading_error.m:054: `int'. ambiguous_overloading_error.m:059: In clause for predicate `ambig_overload1'/1: ambiguous_overloading_error.m:059: error: excessively ambiguous overloading. -ambiguous_overloading_error.m:059: The following symbol was overloaded in the +ambiguous_overloading_error.m:059: The following symbol was overloaded in the ambiguous_overloading_error.m:059: following contexts. ambiguous_overloading_error.m:057: ambiguous_overloading_error.m:057: The function symbol `f'/0. @@ -21,7 +21,7 @@ ambiguous_overloading_error.m:059: Warning: the variable `L' i ambiguous_overloading_error.m:059: term containing itself. ambiguous_overloading_error.m:062: In clause for predicate `ambig_overload2'/1: ambiguous_overloading_error.m:062: warning: highly ambiguous overloading. -ambiguous_overloading_error.m:062: The following symbols were overloaded in +ambiguous_overloading_error.m:062: The following symbols were overloaded in ambiguous_overloading_error.m:062: the following contexts. ambiguous_overloading_error.m:062: ambiguous_overloading_error.m:062: The function symbol `a1'/0. @@ -39,7 +39,7 @@ ambiguous_overloading_error.m:062: the type constructor ambiguous_overloading_error.m:062: `ambiguous_overloading_error.qux'/0. ambiguous_overloading_error.m:116: In clause for predicate `test_lt'/1: ambiguous_overloading_error.m:116: error: excessively ambiguous overloading. -ambiguous_overloading_error.m:116: The following symbol was overloaded in the +ambiguous_overloading_error.m:116: The following symbol was overloaded in the ambiguous_overloading_error.m:116: following contexts. ambiguous_overloading_error.m:067: ambiguous_overloading_error.m:067: The predicate symbol `<'/2. @@ -60,7 +60,7 @@ ambiguous_overloading_error.m:078: That symbol is also overloaded here. ambiguous_overloading_error.m:126: In clause for predicate ambiguous_overloading_error.m:126: `set_browser_param_from_option_table'/3: ambiguous_overloading_error.m:126: warning: highly ambiguous overloading. -ambiguous_overloading_error.m:126: The following symbol was overloaded in the +ambiguous_overloading_error.m:126: The following symbol was overloaded in the ambiguous_overloading_error.m:126: following contexts. ambiguous_overloading_error.m:121: ambiguous_overloading_error.m:121: The function symbol diff --git a/tests/invalid/bad_ambiguity_msg.err_exp b/tests/invalid/bad_ambiguity_msg.err_exp index 4ad03b932..399968f2e 100644 --- a/tests/invalid/bad_ambiguity_msg.err_exp +++ b/tests/invalid/bad_ambiguity_msg.err_exp @@ -1,6 +1,6 @@ bad_ambiguity_msg.m:035: In clause for predicate `main'/2: bad_ambiguity_msg.m:035: error: unresolved type ambiguity. -bad_ambiguity_msg.m:035: The following symbol was overloaded in the following +bad_ambiguity_msg.m:035: The following symbol was overloaded in the following bad_ambiguity_msg.m:035: context. bad_ambiguity_msg.m:038: bad_ambiguity_msg.m:038: The predicate symbol `append'/3. diff --git a/tests/invalid/max_error_line_width.err_exp b/tests/invalid/max_error_line_width.err_exp index 0119ba27d..e0d050e87 100644 --- a/tests/invalid/max_error_line_width.err_exp +++ b/tests/invalid/max_error_line_width.err_exp @@ -2,7 +2,7 @@ max_error_line_width.m:056: In clause for predicate `ambig_overload1'/1: max_error_line_width.m:056: error: excessively ambiguous overloading. max_error_line_width.m:056: This caused the type checker to exceed its limits. It may also make your code difficult to max_error_line_width.m:056: understand. -max_error_line_width.m:056: The following symbol was overloaded in the following contexts. +max_error_line_width.m:056: The following symbol was overloaded in the following contexts. max_error_line_width.m:054: max_error_line_width.m:054: The function symbol `f'/0. max_error_line_width.m:054: The possible matches are: @@ -15,7 +15,7 @@ max_error_line_width.m:059: In clause for predicate `ambig_overload2'/1: max_error_line_width.m:059: warning: highly ambiguous overloading. max_error_line_width.m:059: This may cause type-checking to be very slow. It may also make your code difficult to max_error_line_width.m:059: understand. -max_error_line_width.m:059: The following symbols were overloaded in the following contexts. +max_error_line_width.m:059: The following symbols were overloaded in the following contexts. max_error_line_width.m:059: max_error_line_width.m:059: The function symbol `a1'/0. max_error_line_width.m:059: The possible matches are: @@ -30,7 +30,7 @@ max_error_line_width.m:113: In clause for predicate `test_lt'/1: max_error_line_width.m:113: error: excessively ambiguous overloading. max_error_line_width.m:113: This caused the type checker to exceed its limits. It may also make your code difficult to max_error_line_width.m:113: understand. -max_error_line_width.m:113: The following symbol was overloaded in the following contexts. +max_error_line_width.m:113: The following symbol was overloaded in the following contexts. max_error_line_width.m:064: max_error_line_width.m:064: The function symbol `unchecked_left_shift'/2. max_error_line_width.m:064: The possible matches are: @@ -51,7 +51,7 @@ max_error_line_width.m:123: In clause for predicate `set_browser_param_from_opti max_error_line_width.m:123: warning: highly ambiguous overloading. max_error_line_width.m:123: This may cause type-checking to be very slow. It may also make your code difficult to max_error_line_width.m:123: understand. -max_error_line_width.m:123: The following symbol was overloaded in the following contexts. +max_error_line_width.m:123: The following symbol was overloaded in the following contexts. max_error_line_width.m:118: max_error_line_width.m:118: The function symbol `lookup_bool_option'/2. max_error_line_width.m:118: The possible matches are: diff --git a/tests/warnings/ambiguous_overloading.err_exp b/tests/warnings/ambiguous_overloading.err_exp index f26ecc0ef..bb1d923ab 100644 --- a/tests/warnings/ambiguous_overloading.err_exp +++ b/tests/warnings/ambiguous_overloading.err_exp @@ -4,7 +4,7 @@ ambiguous_overloading.m:045: the preceding `:- import_module' declaration for ambiguous_overloading.m:045: module `int'. ambiguous_overloading.m:048: In clause for predicate `ambig_overload1'/1: ambiguous_overloading.m:048: warning: highly ambiguous overloading. -ambiguous_overloading.m:048: The following symbol was overloaded in the +ambiguous_overloading.m:048: The following symbol was overloaded in the ambiguous_overloading.m:048: following context. ambiguous_overloading.m:048: ambiguous_overloading.m:048: The function symbol `f'/0. @@ -16,7 +16,7 @@ ambiguous_overloading.m:048: the type constructor ambiguous_overloading.m:048: `ambiguous_overloading.foo'/0. ambiguous_overloading.m:052: In clause for predicate `ambig_overload2'/1: ambiguous_overloading.m:052: warning: highly ambiguous overloading. -ambiguous_overloading.m:052: The following symbols were overloaded in the +ambiguous_overloading.m:052: The following symbols were overloaded in the ambiguous_overloading.m:052: following contexts. ambiguous_overloading.m:052: ambiguous_overloading.m:052: The function symbol `a1'/0. @@ -34,7 +34,7 @@ ambiguous_overloading.m:052: the type constructor ambiguous_overloading.m:052: `ambiguous_overloading.qux'/0. ambiguous_overloading.m:063: In clause for predicate `test_lt'/1: ambiguous_overloading.m:063: warning: highly ambiguous overloading. -ambiguous_overloading.m:063: The following symbol was overloaded in the +ambiguous_overloading.m:063: The following symbol was overloaded in the ambiguous_overloading.m:063: following contexts. ambiguous_overloading.m:057: ambiguous_overloading.m:057: The predicate symbol `<'/2. @@ -49,7 +49,7 @@ ambiguous_overloading.m:062: That symbol is also overloaded here. ambiguous_overloading.m:084: In clause for predicate ambiguous_overloading.m:084: `set_browser_param_from_option_table'/3: ambiguous_overloading.m:084: warning: highly ambiguous overloading. -ambiguous_overloading.m:084: The following symbol was overloaded in the +ambiguous_overloading.m:084: The following symbol was overloaded in the ambiguous_overloading.m:084: following contexts. ambiguous_overloading.m:079: ambiguous_overloading.m:079: The function symbol `lookup_bool_option'/2.