Skip to content
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

Type mismatch with pattern matching and lets #1686

Closed
gebner opened this issue Oct 4, 2022 · 4 comments
Closed

Type mismatch with pattern matching and lets #1686

gebner opened this issue Oct 4, 2022 · 4 comments

Comments

@gebner
Copy link
Member

gebner commented Oct 4, 2022

import Lean
open Lean Meta

def substIssue (hLocalDecl : LocalDecl) : MetaM Unit := do
  let error {α} _ : MetaM α := throwError "{hLocalDecl.type}"
  let some (_, lhs, rhs) ← matchEq? hLocalDecl.type | error ()
  error ()

prints:

extracted.lean:4:4: error: type mismatch at `_x.77`, value has type
  EStateM.Result Exception PUnit _y.240
but is expected to have type
  EStateM.Result Exception PUnit α

Nightly: leanprover/lean4:nightly-2022-10-04

@leodemoura
Copy link
Member

@hargoniX The type error occurs after the extendJoinPointContext. Some observations

  • findJoinPoints converts the local function error into a join point. This creates a special situation because we now have a join point that takes a type parameter α as an argument.
  • The function LocalDecl.type is inlined and a nested join point. The nested join point depends on α
  • extendJoinPointContext abstracts α in this nested join point producing type incorrect code.

One solution is to track whether the parameter occurs in a type and don't abstract it. Another option is to invoke the transformation only on phase 2 after we have erased type parameters.

cc @digama0

@leodemoura
Copy link
Member

I will disable the extendJoinPointContext pass for now to make sure @gebner can bump mathlib.

@leodemoura
Copy link
Member

@hargoniX I didn't look at the bug in detail, but I think we can fix this issue by applying the substitution from free-variables to parameters to all types. For example, the type of the nested join point should be

MessageData →
Core.Context →
ST.Ref PUnit Core.State →
Type → Context → PUnit → ST.Ref PUnit State → Expr → EStateM.Result Exception PUnit _y.240 --- << instead of alpha

@hargoniX
Copy link
Contributor

hargoniX commented Oct 5, 2022

Taking a look!

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

No branches or pull requests

3 participants