spec: primitive-type-checker: Recurse into lists.
authorRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:43:31 +0000 (08:43 +0100)
committerRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:43:31 +0000 (08:43 +0100)
* language/aws/spec.scm (primitive-type-checker): Use the
primitive-type-checker recursively for list values that are (wrappers
around) primitive types.

language/aws/spec.scm

index 3a6614b27660ba19e2e156a144a877a7d2b2dafd..a4c56eee0cca86b63ea17c7201cc398a296b2f4c 100644 (file)
@@ -70,13 +70,24 @@ if this is not a primitive data type."
     ("list"
      (let ((member-spec (assoc-ref exp "member")))
        (if member-spec
-           `(lambda (value)
-              (let ((shape ',(string->symbol (assoc-ref member-spec "shape"))))
-                (and (list? value)
-                     (every (lambda (item)
-                              (and=> (aws-name item)
-                                     (cut eq? <> shape)))
-                            value))))
+           (let ((shape-name (string->symbol (assoc-ref member-spec "shape"))))
+             `(lambda (value)
+                (let ((shape ',shape-name))
+                  (and (list? value)
+                       ;; Use the primitive type checker here as well
+                       ;; in case the member spec is a wrapper around
+                       ;; a primitive value.
+                       (every ,(let ((target-spec (assoc-ref %shape-specs shape-name)))
+                                 (if (and=> target-spec primitive?)
+                                     ;; Apply the primitive type check
+                                     ;; directly.  This allows us to
+                                     ;; avoid unnecessary wrapping.
+                                     (primitive-type-checker target-spec)
+                                     ;; Otherwise make sure the value has the correct type
+                                     '(lambda (item)
+                                        (and=> (aws-name item)
+                                               (cut eq? <> shape)))))
+                              value)))))
            'list?)))
     ("map"
      `(lambda (value)