Skip to content

Lean: newtype test fails #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
protoben opened this issue Mar 11, 2025 · 2 comments
Open

Lean: newtype test fails #1147

protoben opened this issue Mar 11, 2025 · 2 comments
Labels
Lean Issues with Sail to Lean translation

Comments

@protoben
Copy link
Collaborator

The newtype Lean test fails with the following message:

error: ././././Out.lean:99:2: invalid match-expression, pattern contains metavariables
  C w
error: Lean exited with code 1
@protoben protoben added the Lean Issues with Sail to Lean translation label Mar 11, 2025
@ineol
Copy link
Collaborator

ineol commented Mar 28, 2025

@bacam How does Coq deal with this?

It seems that it boils down to this, with n being unconnected to the constructor C, and a quick test with jsCoq online didn't work...

Inductive constrained {n : nat} (*member_Z_list n [32; 64]*) :=
| C : nat -> constrained.
Arguments constrained : clear implicits.


Definition main '(tt : unit) : unit :=
   let z := C 32 in
   match z with | C w => tt end.

For completeness, the input program is the following:

newtype wrapper = Wrapper : bits(5)

newtype constrained('n), 'n in {32, 64} = C : int('n)

function main() -> unit = {
  let x = Wrapper(0b00100);
  match x {
    Wrapper(y) => print_bits("y = ", y)
  };
  let z = C(32);
  match z {
    C(w) => print_int("w = ", w)
  }
}

@bacam
Copy link
Contributor

bacam commented Mar 28, 2025

It's currently an expected failure (BTW, there are reasons for expected failures in test/c/run_tests.py). Really, we only need one of the type-level and term-level integers to appear in the translation, a bit like the merging we do for functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lean Issues with Sail to Lean translation
Projects
None yet
Development

No branches or pull requests

3 participants