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

KEEP for custom equals in inline classes #338

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

grechkovlad
Copy link

No description provided.

}
```

Type of `other` will be erased during compilation and passing argument will not require boxing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not erased, but unboxed.


More precise, we define typed equals as a function such that:

* Has name `"equals"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to make examples conform the restrictions. For example, the one above does not have the annotation.

### Inline classes over inline classes

Suppose we have an inline class `B` over inline class `A` and `A` declares typed equals. In this case,
default-generated equals in `B` will be comparing it underlying values using custom equals of `A`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will B require opt-in?

Copy link
Author

@grechkovlad grechkovlad Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Any usage of A will require opt-in and B will use A in its primary constructor declaration

}

@Override
public boolean equals(Object other) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, this equals does not follow its contract. Second, how typed equals will be compiled into Valhalla class method?


### Resolving references to typed equals in compiler frontend

Currently `'=='` operator is being resolved to typed equals in compiler backend, but resolving it in frontend could let
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current decision is that == is never resolved on front-end, but IDE makes everything it can to resolve it. So, it is not about FE support, but rather IDE one.

@grechkovlad grechkovlad marked this pull request as draft December 20, 2022 14:25
@grechkovlad grechkovlad marked this pull request as ready for review December 20, 2022 14:27
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