spec: compile-shape: Prefer primitive type checkers for members.
authorRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:44:49 +0000 (08:44 +0100)
committerRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:44:49 +0000 (08:44 +0100)
* language/aws/spec.scm (compile-shape): Only check for the AWS shape
type if the member value is a complex type and not merely a wrapper
around a primitive type.

language/aws/spec.scm

index a4c56eee0cca86b63ea17c7201cc398a296b2f4c..c40367b8dd3d858c0bab0ba7c9e30aeee132b882 100644 (file)
@@ -148,10 +148,19 @@ if this is not a primitive data type."
                   ;; Type checks
                   ,@(map (match-lambda
                            ((name . spec)
-                            (let ((key-name (string->symbol name)))
+                            (let* ((key-name (string->symbol name))
+                                   (target-shape (string->symbol (assoc-ref spec "shape")))
+                                   (target-spec (assoc-ref %shape-specs target-shape)))
                               `(unless (eq? ,key-name '__unspecified__)
-                                 (ensure ,key-name
-                                         ',(string->symbol (assoc-ref spec "shape")))))))
+                                 ,(if (and=> target-spec primitive?)
+                                      ;; Apply the primitive type
+                                      ;; check directly.  This allows
+                                      ;; us to avoid unnecessary
+                                      ;; wrapping.
+                                      `(,(primitive-type-checker target-spec) ,key-name)
+                                      ;; Otherwise make sure the value has the correct type
+                                      `(ensure ,key-name
+                                               ',(string->symbol (assoc-ref spec "shape"))))))))
                          members)
                   (aws-structure
                    ',scm-name