[ fix ] fix shadowing issue in record elaboration and reflection #3502
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes an issue brought up in #3501. The change in #3468 causes a regression in record elaboration where the outer name is used when shadowing. The following fails to compile:
If the
n
in the lambda is replaced byz
, it succeeds.The root cause is that record elaboration is calling unelaboration with
NoSugar True
, which tries to make the names unique. It changesn
to{n:0}
, but neglects to update the instances ofn
under the binder. This is the same issue as #2084 filed by @buzden.I was initially going to address this by switching to
NoSugar False
, but I figured I would fix #2084 instead and make unelaboration work correctly. The root issue is that the unelaborator is making a fresh variable and using it in the emitted lambda expression, but it processes thesc
with the originalx :: vars
.I've included the reduced test case from #3501 and verified that it fixes the reported issue in
Thin/Internal.idr
. (The problem withcong
noted at the top of that bug report is expected behavior from an earlier breaking change.) I've also included the test case linked from #2084, swapping out the commented lines so it would verifyT
is the same asT''
.