Skip to content

clone: datatype-type override crashes (CoreIncompatible) when an operator matches on a constructor #1046

Open

Description

@strub

When a datatype's type is overridden during cloning, an operator whose body
pattern-matches on the datatype's constructors (i.e. compiles to OP_Fix)
triggers an anomaly during the operator-compatibility check.

MRE

theory Thy.
  type ATy = [ CB of int ].
  op getit (x : ATy) = with x = CB n => n.
end Thy.

clone Thy as Thy1.

clone Thy as Thy2 with
  type ATy = Thy1.ATy,
  op getit <= Thy1.getit.

Result:

anomaly: EcLib.EcTheoryReplay.CoreIncompatible

Reproduces on main in both override modes (type ATy = ... and type ATy <- ...).

Cause

Same root cause as #989: when a datatype's type is overridden, the source
datatype's constructors are not re-created in the clone, so references to them
must be redirected to the target datatype's constructors.
EcTheoryReplay.replay_tyd performs this redirect only for OP_Constr
references, not for OP_Fix match bodies.

PR #1045 (fixing #989) extends the redirect to plain constructor references in
both override modes, but does not widen it to OP_Fix.

Activity

  1. MavenRain commented on Jul 31, 2026

    @MavenRain

    I'd like to take this one. I have a fix working locally: the redirect added in #1045 registers the
    target constructors through EcSubst.add_opdef, which only rewrites constructors where they appear
    as operator expressions. A match body stores each branch's constructor as a bare path in
    opb_ctor, and that goes through the path map instead, so the branch constructors kept pointing at
    the source datatype and the compatibility check compared unequal paths. Recording the redirect in a
    small dedicated map that is consulted where opb_ctor is substituted fixes both override modes; it
    has to stay out of the general path map, since that one is applied recursively through path
    qualifiers and constructors share a namespace with sub-theories and types. I'll open a PR with a
    regression test shortly.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions