-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for var
in refinements
#19982
Conversation
@@ -1943,12 +1943,26 @@ object desugar { | |||
case AndType(tp1, tp2) => stripToCore(tp1) ::: stripToCore(tp2) | |||
case _ => defn.AnyType :: Nil | |||
} | |||
|
|||
val refinements1 = refinements.flatMap { |
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.
It's more efficient to make this a refinements.mapConserve(...).flatten
. If there are no var
refinements this will then never copy the trees.
case tree: ValDef if tree.mods.is(Mutable) => | ||
val getter = | ||
cpy.DefDef(tree)(name = tree.name, paramss = Nil, tpt = tree.tpt, rhs = tree.rhs) | ||
.withMods(Modifiers(tree.mods.flags & (AccessFlags | Synthetic), tree.mods.privateWithin)) |
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.
This expression appears twice and could be lifted out. Also, one can use withFlags
.
val mods1 = tree.mods.withFlags(tree.mods.flags & AccessFlags | Synthetic)
val setter = | ||
cpy.DefDef(tree)(name = tree.name.setterName, paramss = (setterParam :: Nil) :: Nil, tpt = untpd.scalaUnit, rhs = EmptyTree) | ||
.withMods(Modifiers(tree.mods.flags & (AccessFlags | Synthetic), tree.mods.privateWithin)) | ||
List(getter, setter) |
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.
If we go with mapConserve
, this will be Thicket(getter, setter)
cpy.DefDef(tree)(name = tree.name.setterName, paramss = (setterParam :: Nil) :: Nil, tpt = untpd.scalaUnit, rhs = EmptyTree) | ||
.withMods(Modifiers(tree.mods.flags & (AccessFlags | Synthetic), tree.mods.privateWithin)) | ||
List(getter, setter) | ||
case tree => tree :: Nil |
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.
If we go with mapConserve
, this will be tree
.
@@ -431,6 +431,7 @@ EndMarkerTag ::= id | ‘if’ | ‘while’ | ‘for’ | ‘match’ | | |||
### Definitions | |||
```ebnf | |||
RefineDcl ::= ‘val’ ValDcl | |||
| ‘var’ ValDcl |
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.
Same change needed in reference/syntax.md
.
Co-authored-by: Anna Herlihy <[email protected]> Co-authored-by: Nicolas Stucki <[email protected]>
This has been decided to be included in the 3.5.0 release. |
Closes #19809