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

failed to synthesize reported at the beginning of a file #4880

Closed
3 tasks done
adomani opened this issue Jul 31, 2024 · 2 comments · Fixed by #4926
Closed
3 tasks done

failed to synthesize reported at the beginning of a file #4880

adomani opened this issue Jul 31, 2024 · 2 comments · Fixed by #4926
Labels
bug Something isn't working P-medium We may work on this issue if we find the time

Comments

@adomani
Copy link

adomani commented Jul 31, 2024

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

Sometimes, when the auto-filled in by infer_instance parameter fails to find an instance, it reports the error at the beginning of the file, instead of where the failure happened.

Context

Reported on the Lean Zulip.

Steps to Reproduce

Run this code:

  -- <-- `failed to synthesize A` here
class A

structure B where
  h1 : A := by infer_instance
-- using `inferInstance` instead of `by infer_instance` reports the
-- `failed to synthesize A` and the diagnostic comment here
-- not on the `example` below

example : B where

Expected behavior: The error should highlight example.

Actual behavior: The error highlights the beginning of the file.

Versions

[Output of #eval Lean.versionString]

"4.10.0-rc2"

for both the online server and my own computer.

[OS version, if not using live.lean-lang.org.]

Linux Mint

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@adomani adomani added the bug Something isn't working label Jul 31, 2024
@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Aug 2, 2024
@kmill
Copy link
Collaborator

kmill commented Aug 5, 2024

Could you clarify what you expect when it is := inferInstance? In that case, the error is on inferInstance, but that's because the original inferInstance fails to elaborate and the default value for B.h1 becomes sorry.

@adomani
Copy link
Author

adomani commented Aug 6, 2024

Looking again at this, I am not sure what I would expect with inferInstance. It seems that

class A

structure B where
  h1 : A := inferInstance

is already an error, so this is unrelated to the presence of the example. If default values such as this are not allowed, then the error is reported in the right place!

So, the only issue here, from my perspective, is the reporting of the error at the beginning of the file, rather that on example when the default value is set to by infer_instance.

kmill added a commit to kmill/lean4 that referenced this issue Aug 6, 2024
Autoparam tactic scripts have no source positions, which previously made it so that any errors or messages would be logged at the current ref, which was the application or structure instance being elaborated.

However, with incrementality the ref is now carefully managed to avoid leakage of outside data. This prevents the elaborator's ref from being used as the tactic's ref, causing errors to be misplaced.

To fix this, now the elaborators insert the ref's source positions everywhere into the autoparam tactic script.

Closes leanprover#4880
github-merge-queue bot pushed a commit that referenced this issue Aug 6, 2024
Autoparam tactic scripts have no source positions, which until recently
made it so that any errors or messages would be logged at the current
ref, which was the application or structure instance being elaborated.
However, with the new incrementality features the ref is now carefully
managed to avoid leakage of outside data. This inhibits the elaborator's
ref from being used for the tactic's ref, causing messages to be placed
at the beginning of the file rather than on the syntax that triggered
the autoparam.

To fix this, now the elaborators insert the ref's source position
everywhere into the autoparam tactic script.

If in the future messages for synthetic tactics appear at the tops of
files in other contexts, we should consider an approach where
`Lean.Elab.Term.withReuseContext` uses something like `replaceRef` to
set the ref while disabling incrementality when the tactic does not
contain source position information.

Closes #4880
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium We may work on this issue if we find the time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants