-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Change to new given syntax #7210
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
I'm curious why the colon between identifier and curly brace? |
@@ -152,14 +152,14 @@ object Instances extends Common { | |||
object PostConditions { | |||
opaque type WrappedResult[T] = T | |||
|
|||
private given WrappedResult { | |||
private given extension WrappedResult: { | |||
def apply[T](x: T): WrappedResult[T] = x |
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.
With the :
the it starts looking a bit to similar to a structural type.
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.
Do we really need the :
here given that we already have the extension
keyword?
I have now changed the syntax to given ops: extension { ... } I believe that way it is more regular:
With collective extension parameters it's given ops: extension [T](x: S) { ... } I believe that is clearer than the given extension ops[T](x: S) { ... } This second alternative makes it look like |
Sorry if I misunderstand something, but comparing Why not have just |
The third variation of the theme drops the extension identifier again. So it's given { ... }
given ops: { ... } In the end,
given X {
def (x: T) foo (y: T)
} If one adds an given extension X {
def (x: T) foo (y: T)
} Now,
given foo: extension[T](x: T) { ... } with given foo: extensn[T](x: T) { ... } The two meanings are radically different. In the first case In the end, I believe it is better like this:
The rules are quite simple and clear that way. |
c259790
to
dcbc5b4
Compare
3d97e85
to
10668ab
Compare
It's given extension { ... } or given extension ops: { ... }
Change from ``` given extension foo: { ... } ``` to ``` given foo: extension { ... } ``` The new syntax is more regular and pleasing to the eye. It avoids the unusual `: { ... }` symbol combination.
We should get to a new stabilized "given" syntax first. Once that is done, shapeless can be updated and re-integrated.
Drop `given match` and `implict match` syntax. The docs on typeclass derivation still have to be updated to conform to the new terminology.
We have a migration problem for implicit function types and closures. We cannot go in one step from ``` given A => B given (x: A) => B ``` to ``` (given A) => B (given x: A) => B ``` because this becomes ambiguous inside parentheses. We have to migrate using intermediate steps: 1. re-allow delegate instead of given for these types and closures 2. disallow given in the old position, and migrate all code over to delegate 3. allow given in the new position. 4. disallow delegate and migrate all code over to given in the new position.
Replace with `delegate A => B` in tests and with `ImplicitFunctionType[A, B]` in bootstrap code. Also replace `given x: T => e` with `delegate x: T => e`, except in bootstrap code, where the latter is not legal. These measures are necessary for migration to new given scheme.
Drop given parameters that come after the implemented type, since these will not be allowed in the future. We cannot disable the feature right now, since bootstrap code uses it.
The chnages to imports broke the rename test outputs. We should come back o fix this. I'll open an issue.
The new given import syntax required a wholesale refactorings of imports. It's shorter, clearer, and more strictly typed now.
e8ec617
to
9fe3f70
Compare
This comment has been minimized.
This comment has been minimized.
This PR is maximally lenient, allowing all kinds of syntaxes:
The reason is that bootstrap code currently uses both of the superseded styles. The idea is to merge this PR into the next bootstrap compiler. Then restrict everything to the new syntax and fix all code and remaining tests to conform to it. |
To be able to remove remnants of the old given/delegate syntaxes.
@@ -171,7 +171,7 @@ class CommunityBuildTest { | |||
extraSbtArgs = Seq("-Dscala.build.compileWithDotty=true") | |||
) | |||
|
|||
@Test def shapeless = test( | |||
/*@Test*/ def shapeless = test( |
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.
TODO: Open an issue for this
@@ -89,7 +89,7 @@ class RenameTest { | |||
testRenameFrom(m4) | |||
} | |||
|
|||
@Test def renameRenamedImport: Unit = { | |||
/*@Test*/ def renameRenamedImport: Unit = { |
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.
TODO create an issue to update these tests
Highlight the `given` in imports as a keyword and names as type entities. As implemented in scala/scala3#7210
Highlight the `given` in imports as a keyword and names as type entities. * As implemented in scala/scala3#7210 * Also fixes scala/scala3#7233
Where can I see the discussion for why the infix EDIT: #7151 |
@odersky Could you comment why use |
This PR implements the
given
syntax changes described inhttps://github.com/lampepfl/dotty/tree/master/docs/docs/reference/contextual-new