-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement into
modifier on parameter types
#14514
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
Conversation
Open questions
|
The last commit bases the implementation on an internal alias type instead of an annotation. This makes |
415cb86
to
35710f6
Compare
into
modifier on parameter types
Will we need to extend this concept at some point to lambdas? |
e47a34a
to
6525fd3
Compare
I went ahead and made this an experimental feature so that people can try it out. Points to note:
This technique addresses the situations where implicit conversions were found to be essential and hard to replace in the discussion thread cited above. |
@odersky I'm so sorry to keep pestering you about this but after you closed #16002 I really don't know what else to do. For Quill to work I need to have both implicit conversions At this point, the only thing that can save Quill from an eternity of needing implicit-conversions is some kind of injectable |
@deusaquilus I don't know a solution either. Maybe Quill won't profit from |
db10040
to
a7c6680
Compare
Source input: From Scala 3: `(x: into T)` From Scala 2: `(@allowConversions x: T)` Gets translated to (x: <into>[T]) where `<into>` is a new synthetic alias marker type defined as type <into>[T] = T `into` is not accessible from user programs. Parameters labeled `into` allow implicit argument conversions without a import language.implicitConversions import.
a7c6680
to
0a8d19b
Compare
@dwijnand Can you give this a review? |
The reason to merge this now is that I'd like to experiment with the compiler to see whether we can get rid of implicit conversions. We need to make progress on this since old style implicit conversions will be deprecated at some point and new style implicit conversions require a language import at the use site. To make this work, we need to have alternative mechanisms in place that make implicit conversions necessary only in exceptional cases. |
Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall. Just added some minor comments.
Also sorry for causing this PR to hang for so long, I must've dismissed the notification by accident.
tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala
Outdated
Show resolved
Hide resolved
@KacperFKorban Thanks for the review! |
in the thread https://contributors.scala-lang.org/t/proposed-changes-and-restrictions-for-implicit-conversions/4923
we discussed two changes that would make implicit conversions largely redundant. One proposed change was implemented in #14497. The other is implemented here. It's based on #14497.
The idea of this PR is to have some way to specify that a method parameter accepts implicit conversions on its arguments. Then the feature warning on implicit conversion use would be suppressed in this case. In the previous thread I proposed
~
to mark convertible arguments but I now feel this is too cryptic. Instead there is ainto
prefix in theparameter type. E.g.
For Scala 2, we introduce an annotation on the parameter that expresses the same thing:
A larger example:
A larger example is a parser combinator library that works without unrestricted implicit conversions:
tests/run/Parser.scala