From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#68232: [PATCH] Fix range-intersection implementation Date: Thu, 11 Jan 2024 12:56:13 -0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4372"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 68232@debbugs.gnu.org, Lars Magne Ingebrigtsen To: Zachary Romero Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 11 21:57:30 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rO27F-0000w9-Va for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Jan 2024 21:57:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rO26t-0000RO-Oh; Thu, 11 Jan 2024 15:57:07 -0500 Original-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 1rO26r-0000QY-Cj for bug-gnu-emacs@gnu.org; Thu, 11 Jan 2024 15:57:05 -0500 Original-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 1rO26r-0006E9-3k for bug-gnu-emacs@gnu.org; Thu, 11 Jan 2024 15:57:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rO26o-0005u1-Jp for bug-gnu-emacs@gnu.org; Thu, 11 Jan 2024 15:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Jan 2024 20:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68232 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68232-submit@debbugs.gnu.org id=B68232.170500658022621 (code B ref 68232); Thu, 11 Jan 2024 20:57:02 +0000 Original-Received: (at 68232) by debbugs.gnu.org; 11 Jan 2024 20:56:20 +0000 Original-Received: from localhost ([127.0.0.1]:34106 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO267-0005sn-RO for submit@debbugs.gnu.org; Thu, 11 Jan 2024 15:56:20 -0500 Original-Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:44096) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO265-0005sY-Bq for 68232@debbugs.gnu.org; Thu, 11 Jan 2024 15:56:18 -0500 Original-Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2cd0f4797aaso63465711fa.0 for <68232@debbugs.gnu.org>; Thu, 11 Jan 2024 12:56:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705006573; x=1705611373; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=vEmvE34AkUWWHaXXG/pZq1ZMEJ7rOWV++06CRAnp3ls=; b=Lq6E46WepbL8JZvYiGoB59mTkMudIi79kSNcTJkxWPewB7GYcpL6wx46rI7QzsqLkQ XxkSqTDCbA5oZBAQtzqRfoS8uQs3sShoTQ6GWvnmp3d/AHUbKbIkP7JBuGAnxKMvpgSn 0PtHOyeoNagfUrYBEKYr9CC2EMUBctCVdHYLAHH5tRQRUj1HnmCdoLj92sFWe4cyZfjw b6LlP7yvl2jF36O917PfEX41+6rnp08MFbg8QA/UuVGCn3FG3zSO+5hdRANSa3nTnAwI kFx/LDu+6ZKbF6mJIsp/wDbPKDcq7GF/SDPP0LdRpABtZZbDRJqgcuvYNTSSdJ64T+F+ CyVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705006573; x=1705611373; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vEmvE34AkUWWHaXXG/pZq1ZMEJ7rOWV++06CRAnp3ls=; b=dbQDADbTVjkml8pSb23uFAdxFjWUVaQv6+/Tj5xFMk/bvx6Q+qKrhGwJDB+IzJw9eC q91lb63NJr+vbUCxShTyeAR3BGyFXPgnZfxJL17sHK8PKmWgPB6tHKMj9V1i2hamZuOx aRMrxpPcXEIvDm3jzuAp+xGMQ1HVj3TijEULWMAINsOyBFG2SrHvyeaFInasmH0daZ1l yMx5StNnsPWs9JLW7fhVtrSbFQoDwvnohW+gpGsS/lwXCP4d5lJEXBSQb4sY9YCHkTin QrNWYAl/scq+Cxnp5Ojv43wrahZRBNJgE2luLtWD15jbD8PcCKuY2fHdU7fCrvBCfRp6 CT+g== X-Gm-Message-State: AOJu0YwT2aWOJNpehOqeYwrWDFMZisYlutBhdXL74gRvuqRwT3d3ohIj oNQgwKfTFrOhbtONg7BOtV97kHkKVOLL9fQq93w= X-Google-Smtp-Source: AGHT+IHrFvcCNqJuQKLtD67F3ApjEa0gldEx5Q1XR9BaPj81V6ZmNACBNPICalPFHLRDc9jR23ht8aGDwYaxfKGvG7U= X-Received: by 2002:a2e:9b0b:0:b0:2cd:5cfd:b19 with SMTP id u11-20020a2e9b0b000000b002cd5cfd0b19mr169888lji.19.1705006573370; Thu, 11 Jan 2024 12:56:13 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 11 Jan 2024 12:56:13 -0800 In-Reply-To: (Zachary Romero's message of "Wed, 03 Jan 2024 03:30:56 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:277954 Archived-At: Zachary Romero writes: > Hello Emacs maintainers, > > I was using the range package when I encountered a bug in the > implementation of range-intersection. The bug seems to occur when the > ranges involve a mix of integers and cons pairs. The following are some > cases where the current implementation fails to compute the correct > intersection: > > (range-intersection '((1 . 10) 11) '((11 . 12))) > ;; Expects (11), returns nil > > (range-intersection '(11 (13 . 15)) '((13 . 15))) > ;; Expects (13 . 15), returns nil > > (range-intersection '(1 11 13 15) '((1 . 2) (10 . 20))) > ;; Expects (1 11 13 15), returns (1) > > > I also refactored this function using pcase to try to make the steps of > the algorithm more understandable. > > Let me know you thoughts and if there's any further changes I should > make. Thanks for the patch. Could you please add tests for this as well? See the file range-tests.el. Did you check that the existing tests all still pass?