query
On this page

addCheck

lib.types.addCheck

Docs pulled from | This Revision | 9 minutes ago


Augment the given type with an additional type check function.

This function has some broken behavior see: #396021 Fixing is not trivial, we appreciate any help!


Noogle detected

Implementation

The following is the current implementation of this function.

addCheck =
        elemType: check:
        if elemType.merge ? v2 then
          elemType
          // {
            check = {
              __functor = _self: x: elemType.check x && check x;
              isV2MergeCoherent = true;
            };
            merge = {
              __functor =
                self: loc: defs:
                (self.v2 { inherit loc defs; }).value;
              v2 =
                { loc, defs }:
                let
                  orig = checkV2MergeCoherence loc elemType (elemType.merge.v2 { inherit loc defs; });
                  headError' = if orig.headError != null then orig.headError else checkDefsForError check loc defs;
                in
                orig
                // {
                  headError = headError';
                };
            };
          }
        else
          elemType
          // {
            check = x: elemType.check x && check x;
          };