From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id YA1JNY4cTGTh7AAASxT56A (envelope-from ) for ; Fri, 28 Apr 2023 21:20:46 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id UPhFNY4cTGQoEwAAauVa8A (envelope-from ) for ; Fri, 28 Apr 2023 21:20:46 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5F457382B7 for ; Fri, 28 Apr 2023 21:20:46 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=fV9CW7LS; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1682709646; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=a6F/Tzfgmu9C5pOj8XTYIYCAwG3w6VBN4UF4PL6JZXo=; b=QwpkIcQdnMNddhZmwE7EZNo2Y4+zoRSUUKMANOw2a4a+zVPPjoQ3KoAqoUDoZmI2Upo0Cj KDeb6KY5mv5CKS15Gkl1XRxrY1dIY14Rou98L3FGlGWf+iqy4eRy8gj8Nmcl51BhvgcH6F 1557ORrsyXY+OSBc74tZHY4Cuk4fTa60L7NwDcZKbYYlfEoBzsNCwJfLAW3G8E2HJTSlM2 zKz3kdFM1MlgOKRGwXgMyUnyUtjunRIF1M9aTToX8IvpfVZeXCBhQlttyrukbWiZyq+1Rz BXWGrfB4/P8M3/cktxT18i72qaTFP/95M+hgw3sQ13QJP4dGguGNRTujER9Ukg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=fV9CW7LS; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1682709646; a=rsa-sha256; cv=none; b=iCDa3otsfrqQqAZ5KySFIyD368ZHZF+/O+8ddos/q2dVTEmWylaxNE4d1Lh5uQbOwJZ7xD Fd4JwkRXFCQUq0+Rtk8zeaODyzZwYW4TFFSO718GW40S5dDOfcxQM+aH+pW9qG/bb9HeXm XSYVwK5RIMlxtd4HGy6KJb0aEspBFsFYC90HsYFFRqD2Q5xRaLcE2taoLpe6WKF7eB/hbt 4U7YeHBDbzrq/6r8IolIC8StT6sn+g44OjUAZkhRAISw+KE/9rKaBxZ40E6wKNvpGgWtC2 FSMsZNAKXaaFQAoMdPZ2hdvW0EvAhzRyky0FOwCKIkCPkXpNYoS/XEUeTfrh6A== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psTdd-0002S1-Nx; Fri, 28 Apr 2023 15:20:14 -0400 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 1psTdT-0002PR-Vv for guix-patches@gnu.org; Fri, 28 Apr 2023 15:20:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1psTdS-0004FU-WE for guix-patches@gnu.org; Fri, 28 Apr 2023 15:20:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1psTdS-00063J-RL for guix-patches@gnu.org; Fri, 28 Apr 2023 15:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63135] [PATCH v2 2/5] records: match-record: Display more helpful field-not-found error. Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 28 Apr 2023 19:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63135 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63135@debbugs.gnu.org Cc: "\(" , Josselin Poiret Received: via spool by 63135-submit@debbugs.gnu.org id=B63135.168270956023129 (code B ref 63135); Fri, 28 Apr 2023 19:20:02 +0000 Received: (at 63135) by debbugs.gnu.org; 28 Apr 2023 19:19:20 +0000 Received: from localhost ([127.0.0.1]:34536 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psTcm-00060u-FD for submit@debbugs.gnu.org; Fri, 28 Apr 2023 15:19:20 -0400 Received: from knopi.disroot.org ([178.21.23.139]:41434) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psTcj-000607-NQ for 63135@debbugs.gnu.org; Fri, 28 Apr 2023 15:19:19 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 155EA40320; Fri, 28 Apr 2023 21:19:17 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7nB_b2AMIdMi; Fri, 28 Apr 2023 21:19:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1682709555; bh=aa/TNg6F4FuftaCqmdSb5c/md+/36DE3Ku+qtLN2znA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fV9CW7LSXi9ARkPMWRX0vatEhki9vuoVhPNH57YPWP5y7/qSbxi4fZtSgz1qlrGRi ME4U7uMz35JWmjPo8RDzMyr1ywuSMdATBbg3TjmaVs+gVktGS/8iJ+711akgmEvBKS YeLP5rzBjMdHDjVCdXqjhikwxyPrLc1fyXOVndBFH0T7kk4r75wHsfWq26qmOFzGMy gYX+0/QHMZgGdBARfaGn6Mg4qQOKh9LQSwyKRIyVApYgsOKVX4XRWaFJEsHaPwZsH8 neJg9p1J2PxPc5MGX1VPCB7JRBT32sAbbtPDr0D7gBXf0QqoJiceD6euNMaMuU5Y3Q PnlS+T56eQLsA== Date: Fri, 28 Apr 2023 20:19:02 +0100 Message-Id: <20230428191905.13860-3-paren@disroot.org> In-Reply-To: <20230428191905.13860-1-paren@disroot.org> References: <20230428191905.13860-1-paren@disroot.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: UNKNOWN X-Migadu-Spam-Score: -5.05 X-Spam-Score: -5.05 X-Migadu-Queue-Id: 5F457382B7 X-Migadu-Scanner: in3.migadu.com X-TUID: 8kiyMINadfIx * guix/records.scm (match-record): Display MATCH-RECORD as the origin of "unknown record type field" errors. Show the original MATCH-RECORD form, rather than an intermediate LOOKUP-FIELD form, within said errors. --- guix/records.scm | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index d8966998c1..4bee9d0aac 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -582,44 +582,46 @@ (define-syntax lookup-field (lambda (s) "Look up FIELD in the given list and return an expression that represents its offset in the record. Raise a syntax violation when the field is not -found." +found, displaying it as originating in form S*." (syntax-case s () - ((_ field offset ()) - (syntax-violation 'lookup-field "unknown record type field" - s #'field)) - ((_ field offset (head tail ...)) + ((_ s* field offset ()) + (syntax-violation 'match-record + "unknown record type field" + #'s* #'field)) + ((_ s* field offset (head tail ...)) (free-identifier=? #'field #'head) #'offset) - ((_ field offset (_ tail ...)) - #'(lookup-field field (+ 1 offset) (tail ...)))))) + ((_ s* field offset (_ tail ...)) + #'(lookup-field s* field (+ 1 offset) (tail ...)))))) (define-syntax match-record-inner (lambda (s) (syntax-case s () - ((_ record type ((field variable) rest ...) body ...) + ((_ s* record type ((field variable) rest ...) body ...) #'(let-syntax ((field-offset (syntax-rules () ((_ f) - (lookup-field field 0 f))))) + (lookup-field s* field 0 f))))) (let* ((offset (type (map-fields type match-record) field-offset)) (variable (struct-ref record offset))) - (match-record-inner record type (rest ...) body ...)))) - ((_ record type (field rest ...) body ...) + (match-record-inner s* record type (rest ...) body ...)))) + ((_ s* record type (field rest ...) body ...) ;; Redirect to the canonical form above. - #'(match-record-inner record type ((field field) rest ...) body ...)) - ((_ record type () body ...) + #'(match-record-inner s* record type ((field field) rest ...) body ...)) + ((_ s* record type () body ...) #'(begin body ...))))) (define-syntax match-record - (syntax-rules () + (lambda (s) "Bind each FIELD of a RECORD of the given TYPE to it's FIELD name. The order in which fields appear does not matter. A syntax error is raised if an unknown field is queried. The current implementation does not support thunked and delayed fields." ;; TODO support thunked and delayed fields - ((_ record type (fields ...) body ...) - (if (eq? (struct-vtable record) type) - (match-record-inner record type (fields ...) body ...) - (throw 'wrong-type-arg record))))) + (syntax-case s () + ((_ record type (fields ...) body ...) + #`(if (eq? (struct-vtable record) type) + (match-record-inner #,s record type (fields ...) body ...) + (throw 'wrong-type-arg record)))))) ;;; records.scm ends here -- 2.39.2