From patchwork Thu Dec 28 00:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Skyler Ferris X-Patchwork-Id: 58122 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D099827BBEA; Thu, 28 Dec 2023 00:32:17 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id DD14A27BBE2 for ; Thu, 28 Dec 2023 00:32:16 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rIeJk-00041l-Kd; Wed, 27 Dec 2023 19:32:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rIeJi-00041d-P0 for guix-patches@gnu.org; Wed, 27 Dec 2023 19:32:06 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rIeJf-00022h-EF for guix-patches@gnu.org; Wed, 27 Dec 2023 19:32:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rIeJe-0006iv-9D for guix-patches@gnu.org; Wed, 27 Dec 2023 19:32:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#67788] records: Check for missing mandatory innate fields when, inheriting. References: <5a0f596c5bbcc75e3ca50d37066f42baca354236.1702330063.git.skyvine@protonmail.com> In-Reply-To: <5a0f596c5bbcc75e3ca50d37066f42baca354236.1702330063.git.skyvine@protonmail.com> Resent-From: Skyler Ferris Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 28 Dec 2023 00:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67788 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 67788@debbugs.gnu.org Received: via spool by 67788-submit@debbugs.gnu.org id=B67788.170372348425167 (code B ref 67788); Thu, 28 Dec 2023 00:32:02 +0000 Received: (at 67788) by debbugs.gnu.org; 28 Dec 2023 00:31:24 +0000 Received: from localhost ([127.0.0.1]:38102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rIeJ2-0006XZ-2L for submit@debbugs.gnu.org; Wed, 27 Dec 2023 19:31:24 -0500 Received: from mail-4322.protonmail.ch ([185.70.43.22]:57875) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rIeIz-0006Q6-W0 for 67788@debbugs.gnu.org; Wed, 27 Dec 2023 19:31:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1703723476; x=1703982676; bh=Er58yMHg0xcrWVUmZeu1WLbmedDfbUG9f8BkyJclMDg=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=tZee5fCym6LkFfheXt2vwt7bkM9A+VGlVnHnVYm/NqpY1DoBjz2ifXBTc34ZIb2+N aJsbivwLCvqLzz9WWEgAIVjmPET9p6tSa3uCIlYvqIBfRL95TPPPVmqrJuA5CojNZT 6RpvxLxKIWeYTi3QpljXXu/gSvdr/bDbVgIKGiS68ncLFxH82KyiG61XNzDUB3iwuV sjYlw+lQUBxtfDFivPJIY3LGt3YO6EFMrbxXltWqDRnMEFxpAH/94q0CnPW/GgWmKQ y3MZzM9ws0KYxGtY2cBVdk76kaRUE+79NjcnnGFH+I6MB5T5wyYz/U2fErg4df2D9T NS1CqrC20vxNg== Date: Thu, 28 Dec 2023 00:30:56 +0000 Message-ID: Feedback-ID: 40635331:user:proton MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Skyler Ferris X-ACL-Warn: , Skyler Ferris via Guix-patches X-Patchwork-Original-From: Skyler Ferris via Guix-patches via From: Skyler Ferris Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches his gives the user a more helpful error message if they inherit from another instance but forget to supply a value for a field which is innate and has no default. * guix/records.scm (record-inheritance): Check for missing innate fields Change-Id: I08b898d8da551af50aa5b0b60187dcad8d259bc1 --- # This version of the commit addse a test case which confirms that # theuseful commit message is given. It is based on the test immediately # above it, which checks for the error message in the non-innate case. # # Additionally, I can now confirm that all tests pass with this commit. # The failures I noted previously were indeed environmental problems and # have been resolved locally (and were unrelated to the commit).  guix/records.scm  |  9 +++++++++  tests/records.scm | 18 ++++++++++++++++++  2 files changed, 27 insertions(+) base-commit: fe86819d8bde674766659c22b215d3a689a8026e diff --git a/guix/records.scm b/guix/records.scm index f4d12a861d..109c5cf4dc 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -161,6 +161,15 @@ (define-syntax make-syntactic-constructor                 (record-error 'name s "extraneous field initializers ~a"                               unexpected))) +           ;; Make sure all mandatory and innate fields are included. +           (let* ((fields           (map (compose car syntax->datum) field+value)) +                  (optional         (map (compose car syntax->datum) 'defaults)) +                  (mandatory        (lset-difference eq? '(expected ...) optional)) +                  (mandatory+innate (lset-intersection eq? mandatory 'innate)) +                  (missing          (lset-difference eq? mandatory+innate fields))) +             (when (pair? missing) +               (record-error 'name s "missing field initializers ~a" missing))) +             #`(make-struct/no-tail type                            #,@(map (lambda (field index)                                      (or (field-inherited-value field) diff --git a/tests/records.scm b/tests/records.scm index 5464892d3b..39f4bfdf9c 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -402,6 +402,24 @@ (define (location-alist loc)             (string-match "missing .*initialize.*baz" message)             (equal? form '(foo)))))) +(test-assert "define-record-type* & innate & missing initializers" +  (catch 'syntax-error +    (lambda () +      (eval '(begin +               (define-record-type* foo make-foo +                 foo? +                 (bar foo-bar (default 42)) +                 (baz foo-baz (innate))) + +               (let ((base (foo (bar #t) (baz #t)))) +                 (foo (inherit base)))) +            (test-module)) +      #f) +    (lambda (key proc message location form . args) +      (and (eq? proc 'foo) +           (string-match "missing .*initialize.*baz" message) +           (equal? form '(foo (inherit base))))))) +  (test-assert "define-record-type* & extra initializers"    (catch 'syntax-error      (lambda ()