Function: majutsu-template--conditional-node-satisfies-type-p

majutsu-template--conditional-node-satisfies-type-p is a natively compiled function defined in majutsu-template.el.

Signature

(majutsu-template--conditional-node-satisfies-type-p NODE EXPECTED)

Documentation

Return non-nil if conditional NODE can be consumed as EXPECTED.

This follows upstream `if()` behavior more closely: the conditional itself is an
`Any` value, but it can be used as `Template`/`Stringify` only if every branch
supports that capability, and as `Serialize` only if every branch supports that capability and an explicit else branch is present.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-template.el
(defun majutsu-template--conditional-node-satisfies-type-p (node expected)
  "Return non-nil if conditional NODE can be consumed as EXPECTED.
This follows upstream `if()` behavior more closely: the conditional itself is an
`Any` value, but it can be used as `Template`/`Stringify` only if every branch
supports that capability, and as `Serialize` only if every branch supports that
capability and an explicit else branch is present."
  (let* ((args (majutsu-template-node-args node))
         (then-node (cadr args))
         (else-node (caddr args))
         (expected (majutsu-template--type-ref-normalize expected))
         (runtime-expected (majutsu-template--type-check-runtime-expected expected)))
    (pcase (majutsu-template--type-ref-base-type runtime-expected)
      ('Any t)
      ((or 'Template 'Stringify)
       (and then-node
            (majutsu-template--node-satisfies-type-p then-node runtime-expected)
            (or (null else-node)
                (majutsu-template--node-satisfies-type-p else-node runtime-expected))))
      ('Serialize
       (and then-node else-node
            (majutsu-template--node-satisfies-type-p then-node runtime-expected)
            (majutsu-template--node-satisfies-type-p else-node runtime-expected)))
      (_ nil))))