]> Repositorios git - scryer-prolog.git/commitdiff
prioritize type errors over instantiation errors
authorMarkus Triska <[email protected]>
Sat, 14 May 2022 07:52:34 +0000 (09:52 +0200)
committerMarkus Triska <[email protected]>
Sat, 14 May 2022 07:53:21 +0000 (09:53 +0200)
Example:

    ?- must_be(chars, [a,X,cc]).
       error(type_error(character,cc),can_be/2).

See https://github.com/mthom/scryer-prolog/pull/1474#issuecomment-1126664368

src/lib/error.pl

index a7cc4a5a5d09cefb94844aab09f923718697643a..87b3ff46183bb863d1035ee6336c9f116ee6baea 100644 (file)
@@ -1,5 +1,5 @@
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-   Written September 2018 by Markus Triska ([email protected])
+   Written 2018-2022 by Markus Triska ([email protected])
    I place this code in the public domain. Use it in any way you want.
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
@@ -48,6 +48,7 @@ must_be_(integer, Term) :- check_(integer, integer, Term).
 must_be_(atom, Term)    :- check_(atom, atom, Term).
 must_be_(character, T)  :- check_(error:character, character, T).
 must_be_(chars, Ls) :-
+        can_be(chars, Ls), % prioritize type errors over instantiation errors
         must_be(list, Ls),
         (   '$is_partial_string'(Ls) ->
             % The expected case (success) uses a very fast test.