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

Fix implicit syntax collisions #629

Merged

Conversation

vladimirkl
Copy link
Contributor

This PR fixes a collision when we use something like scala-newtype and have import monocle.macros.syntax.lens._ in scope. A cause of collision is val value: A in GenApplyLensOps so it conflicts with any .value that is defined via implicit syntax. The same issue was fixed in Cats code base - see typelevel/cats#2491 and
typelevel/cats#2614.
Proposed change can be considered as binary compatible - unless someone used GenApplyLensOps.value in code which is unlikely. We can probably do a bit more and replace toGenApplyLensOps and GenApplyLensOps with single implicit class - as Scala looks to be not instantiating it for macro based syntax. But this change can break some code using GenApplyLensOps directly, so for now I'm just making .value private and replace access to it in macro with pattern matching on tree.

@julien-truffaut
Copy link
Member

LGTM @vladimirkl thanks for the PR!

Do you know if it applies to any other macros? or other syntax classes?

@julien-truffaut
Copy link
Member

btw does this change only apply to cats branch? if not could you update the PR toward master, we will cherry pick it back to cats on the next realease.

@vladimirkl
Copy link
Contributor Author

I think that issue applies to every syntax class that subject as public field. Btw they are defined inconsistently - some are AnyVal and some are not. I can make them all AnyVal with private val subject. And PR can be renamed to "Fix implicit syntax collisions". I will try to make it against master.

@vladimirkl vladimirkl changed the base branch from cats to master February 19, 2019 14:02
@vladimirkl vladimirkl changed the title Fix GenApplyLensSyntax.value collision Fix implicit syntax collisions Feb 19, 2019
@julien-truffaut
Copy link
Member

Thanks @vladimirkl !

@julien-truffaut julien-truffaut merged commit e2f8212 into optics-dev:master Feb 20, 2019
@vladimirkl
Copy link
Contributor Author

@julien-truffaut should I make a PR for cats branch with cherry pick?

@julien-truffaut
Copy link
Member

it would be great if you have time

vladimirkl added a commit to vladimirkl/Monocle that referenced this pull request Feb 20, 2019
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

Successfully merging this pull request may close these issues.

2 participants