Skip to content

Make convert available without import #11786

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

Merged
merged 1 commit into from
Mar 19, 2021
Merged

Make convert available without import #11786

merged 1 commit into from
Mar 19, 2021

Conversation

rjolly
Copy link
Contributor

@rjolly rjolly commented Mar 17, 2021

No description provided.

given Conversion[String, Int] = _.length
given Conversion[Int, String] = _.toString

def f(x: String): Int = x.convert
def g(x: Int): String = x.convert[String]
def g(x: Int): String = x.convert
Copy link
Member

Choose a reason for hiding this comment

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

This won't work if there are two Conversion[Int, Y] in scope for two different Ys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does with a suitable type ascription, see updated test.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sjrd Looks like @rjolly is right. Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, apparently it works, indeed.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

I think this better than what we had.

given Conversion[String, Int] = _.length
given Conversion[Int, String] = _.toString

def f(x: String): Int = x.convert
def g(x: Int): String = x.convert[String]
def g(x: Int): String = x.convert
Copy link
Contributor

Choose a reason for hiding this comment

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

@sjrd Looks like @rjolly is right. Do you agree?

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Changing the name to ~ is a different battle, and should definitely not be part of this PR.

@rjolly rjolly force-pushed the convert branch 2 times, most recently from bec8412 to ddd7449 Compare March 19, 2021 09:49
@sjrd sjrd merged commit 86e9a42 into scala:master Mar 19, 2021
@rjolly rjolly deleted the convert branch March 19, 2021 16:46
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

4 participants