From 0b1d1a591edbb56054ad2ce7f11119627aec5c82 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Thu, 21 Sep 2023 12:10:45 +0000 Subject: [PATCH] Disallow empty "or" type specifier This fixes an inconsistency in the `or` type specifier when used with an empty argument list, whereas, contrary to how the `(or)` function is `#f`, the `(or)` type specifier is `*`. --- manual/Types | 4 ++-- scrutinizer.scm | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/manual/Types b/manual/Types index f3fb6b7b..27ef0fc6 100644 --- a/manual/Types +++ b/manual/Types @@ -99,7 +99,7 @@ or {{:}} should follow the syntax given below: - + @@ -241,7 +241,7 @@ Procedure types are assumed to be not referentially transparent and are assumed to possibly modify locally held state. Using the {{(... --> ...)}} syntax, you can declare a procedure to not modify local state, i.e. not causing any side-effects on local variables or -data contain in local variables. This gives more opportunities for +data contained in local variables. This gives more opportunities for optimization but may not be violated or the results are undefined. diff --git a/scrutinizer.scm b/scrutinizer.scm index cdf6f205..35f889e2 100644 --- a/scrutinizer.scm +++ b/scrutinizer.scm @@ -75,7 +75,7 @@ ; result specifiers: ; ; SPEC = * | (TYPE1 ...) -; TYPE = (or TYPE1 ...) +; TYPE = (or TYPE1 TYPE2 ...) ; | (not TYPE) ; | (struct NAME) ; | (procedure [NAME] (TYPE1 ... [#!optional TYPE1 ...] [#!rest [TYPE | values]]) . RESULTS) @@ -1911,6 +1911,7 @@ v)) ((eq? 'or (car t)) (and (list? t) + (not (null? (cdr t))) (let ((ts (map validate (cdr t)))) (and (every identity ts) `(or ,@ts))))) -- 2.42.0
VALUETYPEmeaning
{{(or VALUETYPE ...)}}"union" or "sum" type
{{(or VALUETYPE1 VALUETYPE2 ...)}}"union" or "sum" type
{{(not VALUETYPE)}}non-matching type (*)
{{(struct STRUCTURENAME)}}record structure of given kind
{{(procedure [NAME] (VALUETYPE ... [#!optional VALUETYPE ...] [#!rest [VALUETYPE]]) . RESULTS)}}procedure type, optionally with name