]> Repositorios git - scryer-prolog.git/commitdiff
ENHANCED: must_be/2: prefer type error over instantiation error
authorMarkus Triska <[email protected]>
Sun, 26 Feb 2023 21:27:06 +0000 (22:27 +0100)
committerMarkus Triska <[email protected]>
Sun, 26 Feb 2023 21:28:18 +0000 (22:28 +0100)
This addresses #1594.

src/lib/error.pl

index 7efb170ef8c5007d3094a08dc0f71d3d462f100e..38a932140405514cb17b6eaec376b171a9122c9f 100644 (file)
@@ -1,5 +1,5 @@
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-   Written 2018-2022 by Markus Triska ([email protected])
+   Written 2018-2023 by Markus Triska ([email protected])
    I place this code in the public domain. Use it in any way you want.
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
@@ -85,11 +85,11 @@ must_be_(list, Term)    :- check_(error:ilist, list, Term).
 must_be_(type, Term)    :- check_(error:type, type, Term).
 must_be_(boolean, Term) :- check_(error:boolean, boolean, Term).
 must_be_(term, Term)    :-
-        (   \+ ground(Term) ->
-            instantiation_error(must_be/2)
-        ;   \+ acyclic_term(Term) ->
-            type_error(term, Term, must_be/2)
-        ;   true
+        (   acyclic_term(Term) ->
+            (   ground(Term) ->  true
+            ;   instantiation_error(must_be/2)
+            )
+        ;   type_error(term, Term, must_be/2)
         ).
 
 % We cannot use maplist(must_be(character), Cs), because library(lists)