Add finer-grained validation for determining the symbols to defer during symbol processing #3559
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.
This addresses an issue introduced here: #3537 (comment)
Essentially, at the moment, processing for any candidate class for optics is "deferred" when "validation" fails - essentially when any type in the class definition is not resolved. Unfortunately, this causes issues when these types are dependent on the lenses-to-be-generated themselves, such as in the following example:
While this class obviously has unresolved types, these do not impact code generation of optics. Ideally, we should limit the validation to only check the validity of the types involved in the generated lenses. The best place for this would probably be in the
Focus
class after generating the ADT, but I could not get this to work very neatly without changing code everywhere.Instead, I implemented a simpler, "best effort" approach where I skip validation for irrelevant declarations/nodes, such as functions and annotations. This is not perfect, and still causes the validation to be "too strict", but might be a good initial step.
The approach suggested in the other thread - to defer classes once and actually process them on a second pass - does not work, as KSP will stop processing symbols when there is no other processor to defer symbols to.