Skip to content

Soundness: a bare constructor name as a match pattern silently becomes a catch-all binder when the datatype is imported #1716

Closed as not planned

Description

@adeerkhan

What you did

bend PROOF.bend

What happened

$ bend PROOF.bend
ALL PROOFS CHECK
Use --verdict for mathematical validity.
(exit 0)

# The law is FALSE as written. With the intended spelling (case C.Red{}:),
# the same book is correctly refused:
$ bend PROOF.bend
SOME PROOFS FAIL
Error:
- expected : False{}
- observed : True{}
Location: Laws.thm

The file

# ---- code.bend ----
import Base

type Color is Data:
  Red{}
  Green{}

def cleared(c: Color) -> Bool:
  match c:
    case Red{}:
      True{}
    case Green{}:
      True{}

def paint(c: Color) -> Color:
  c

# ---- LAWS.bend ----
import Base
import ./code.bend as C

def safe(c: C.Color) -> Bool:
  match c:
    case Red:          # bare name on an imported datatype
      C.cleared(Red)
    case Green:
      False{}

law thm:
  for c: C.Color
  {safe(C.paint(c)) == True{} : Bool}

# ---- PROOF.bend ----
import Base
import ./code.bend as C
import ./LAWS.bend as Laws

def Laws.thm(c):
  match c:
    case C.Red{}:
      {==}
    case C.Green{}:
      {==}

bend --version

bend 2.0.35

uname -sm

Linux x86_64

clang --version (the first line)

(not installed — built/run with gcc 16.2.1 and bun; the checker path is pure TypeScript)

Activity

  1. added
    bug
    on Oct 18, 2026
  2. nicolas-abril commented on Oct 19, 2026

    @nicolas-abril
    Collaborator

    Thanks for the report. Closing, because the proof result here is correct.

    In the importing file, imported constructors are only in scope qualified (C.Red). So a bare case Red: is a new binder that matches every value. As written, safe returns True{} for every input, which makes safe(C.paint(c)) == True{} true. So "ALL PROOFS CHECK" is the right verdict. The law is only false with the spelling you meant (case C.Red{}:), and the checker refuses that version.

    You're right that the imported case should match the local one, though. In the same file, a bare case Red: gets a preemptive error ("Red is a constructor: write Red{}, or rename the binder"). In an importing file it's silently accepted. Ideally both would give the same error. We'll handle that consistency separately.

    Comment written by an AI assistant on behalf of @nicolas-abril.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions