@@ -26,26 +26,22 @@ object desugar {
26
26
/** If a Select node carries this attachment, suppress the check
27
27
* that its type refers to an acessible symbol.
28
28
*/
29
- val SuppressAccessCheck : Property .Key [Unit ] = new Property .Key
29
+ val SuppressAccessCheck : Property .Key [Unit ] = Property .Key ()
30
30
31
31
/** An attachment for companion modules of classes that have a `derives` clause.
32
32
* The position value indicates the start position of the template of the
33
33
* deriving class.
34
34
*/
35
- val DerivingCompanion : Property .Key [SourcePosition ] = new Property .Key
35
+ val DerivingCompanion : Property .Key [SourcePosition ] = Property .Key ()
36
36
37
37
/** An attachment for match expressions generated from a PatDef or GenFrom.
38
38
* Value of key == one of IrrefutablePatDef, IrrefutableGenFrom
39
39
*/
40
- val CheckIrrefutable : Property .Key [MatchCheck ] = new Property .StickyKey
41
-
42
- /** What static check should be applied to a Match (none, irrefutable, exhaustive) */
43
- class MatchCheck (val n : Int ) extends AnyVal
44
- object MatchCheck {
45
- val None = new MatchCheck (0 )
46
- val Exhaustive = new MatchCheck (1 )
47
- val IrrefutablePatDef = new MatchCheck (2 )
48
- val IrrefutableGenFrom = new MatchCheck (3 )
40
+ val CheckIrrefutable : Property .Key [MatchCheck ] = Property .StickyKey ()
41
+
42
+ /** What static check should be applied to a Match? */
43
+ enum MatchCheck {
44
+ case None , Exhaustive , IrrefutablePatDef , IrrefutableGenFrom
49
45
}
50
46
51
47
/** Info of a variable in a pattern: The named tree and its type */
@@ -136,17 +132,17 @@ object desugar {
136
132
def derivedTypeParam (tdef : TypeDef , suffix : String = " " )(implicit ctx : Context ): TypeDef =
137
133
cpy.TypeDef (tdef)(
138
134
name = tdef.name ++ suffix,
139
- rhs = new DerivedFromParamTree (suffix).withSpan(tdef.rhs.span).watching(tdef)
135
+ rhs = DerivedFromParamTree (suffix).withSpan(tdef.rhs.span).watching(tdef)
140
136
)
141
137
142
138
/** A derived type definition watching `sym` */
143
139
def derivedTypeParam (sym : TypeSymbol )(implicit ctx : Context ): TypeDef =
144
- TypeDef (sym.name, new DerivedFromParamTree (" " ).watching(sym)).withFlags(TypeParam )
140
+ TypeDef (sym.name, DerivedFromParamTree (" " ).watching(sym)).withFlags(TypeParam )
145
141
146
142
/** A value definition copied from `vdef` with a tpt typetree derived from it */
147
143
def derivedTermParam (vdef : ValDef )(implicit ctx : Context ): ValDef =
148
144
cpy.ValDef (vdef)(
149
- tpt = new DerivedFromParamTree (" " ).withSpan(vdef.tpt.span).watching(vdef))
145
+ tpt = DerivedFromParamTree (" " ).withSpan(vdef.tpt.span).watching(vdef))
150
146
151
147
// ----- Desugar methods -------------------------------------------------
152
148
@@ -165,7 +161,7 @@ object desugar {
165
161
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
166
162
// right now vdef maps via expandedTree to a thicket which concerns itself.
167
163
// I don't see a problem with that but if there is one we can avoid it by making a copy here.
168
- val setterParam = makeSyntheticParameter(tpt = ( new SetterParamTree ).watching(vdef))
164
+ val setterParam = makeSyntheticParameter(tpt = SetterParamTree ( ).watching(vdef))
169
165
// The rhs gets filled in later, when field is generated and getter has parameters (see Memoize miniphase)
170
166
val setterRhs = if (vdef.rhs.isEmpty) EmptyTree else unitLiteral
171
167
val setter = cpy.DefDef (vdef)(
@@ -217,7 +213,7 @@ object desugar {
217
213
val meth @ DefDef (_, tparams, vparamss, tpt, rhs) = transformQuotedPatternName(meth0)
218
214
val methName = normalizeName(meth, tpt).asTermName
219
215
val mods = meth.mods
220
- val epbuf = new ListBuffer [ValDef ]
216
+ val epbuf = ListBuffer [ValDef ]()
221
217
def desugarContextBounds (rhs : Tree ): Tree = rhs match {
222
218
case ContextBounds (tbounds, cxbounds) =>
223
219
epbuf ++= makeImplicitParameters(cxbounds, Implicit , forPrimaryConstructor = isPrimaryConstructor)
@@ -443,7 +439,7 @@ object desugar {
443
439
val (enumCases, enumStats) = stats.partition(DesugarEnums .isEnumCase)
444
440
if (enumCases.isEmpty)
445
441
ctx.error(" Enumerations must constain at least one case" , namePos)
446
- val enumCompanionRef = new TermRefTree ()
442
+ val enumCompanionRef = TermRefTree ()
447
443
val enumImport = Import (importDelegate = false , enumCompanionRef, enumCases.flatMap(caseIds))
448
444
(enumImport :: enumStats, enumCases, enumCompanionRef)
449
445
}
@@ -456,7 +452,7 @@ object desugar {
456
452
val derivedVparamss = constrVparamss.nestedMap(derivedTermParam(_))
457
453
val arity = constrVparamss.head.length
458
454
459
- val classTycon : Tree = new TypeRefTree // watching is set at end of method
455
+ val classTycon : Tree = TypeRefTree () // watching is set at end of method
460
456
461
457
def appliedTypeTree (tycon : Tree , args : List [Tree ]) =
462
458
(if (args.isEmpty) tycon else AppliedTypeTree (tycon, args))
@@ -766,7 +762,7 @@ object desugar {
766
762
}
767
763
768
764
flatTree(cdef1 :: companions ::: implicitWrappers)
769
- }.reporting(res => i " desugared: $res " , Printers .desugar)
765
+ }.reporting(i " desugared: $result " , Printers .desugar)
770
766
771
767
/** Expand
772
768
*
@@ -844,7 +840,7 @@ object desugar {
844
840
*/
845
841
def normalizeName (mdef : MemberDef , impl : Tree )(implicit ctx : Context ): Name = {
846
842
var name = mdef.name
847
- if (name.isEmpty) name = name.likeSpaced(s " ${inventName(impl)}_instance " .toTermName)
843
+ if (name.isEmpty) name = name.likeSpaced(s " ${inventName(impl)}_given " .toTermName)
848
844
if (ctx.owner == defn.ScalaPackageClass && defn.reservedScalaClassNames.contains(name.toTypeName)) {
849
845
def kind = if (name.isTypeName) " class" else " object"
850
846
ctx.error(em " illegal redefinition of standard $kind $name" , mdef.sourcePos)
@@ -895,8 +891,8 @@ object desugar {
895
891
}
896
892
else x
897
893
}
898
- private val typeNameExtractor = new NameExtractor (followArgs = true )
899
- private val argNameExtractor = new NameExtractor (followArgs = false )
894
+ private val typeNameExtractor = NameExtractor (followArgs = true )
895
+ private val argNameExtractor = NameExtractor (followArgs = false )
900
896
901
897
private def inventTypeName (tree : Tree )(implicit ctx : Context ): String = typeNameExtractor(" " , tree)
902
898
@@ -1207,7 +1203,7 @@ object desugar {
1207
1203
def makeContextualFunction (formals : List [Type ], body : Tree , isErased : Boolean )(implicit ctx : Context ): Tree = {
1208
1204
val mods = if (isErased) Given | Erased else Given
1209
1205
val params = makeImplicitParameters(formals.map(TypeTree ), mods)
1210
- new FunctionWithMods (params, body, Modifiers (mods))
1206
+ FunctionWithMods (params, body, Modifiers (mods))
1211
1207
}
1212
1208
1213
1209
/** Add annotation to tree:
@@ -1419,7 +1415,7 @@ object desugar {
1419
1415
val pdefs = (valeqs, defpats, rhss).zipped.map(makePatDef(_, Modifiers (), _, _))
1420
1416
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom (defpat0, gen.expr, gen.checkMode) :: Nil , Block (pdefs, makeTuple(id0 :: ids)))
1421
1417
val allpats = gen.pat :: pats
1422
- val vfrom1 = new GenFrom (makeTuple(allpats), rhs1, GenCheckMode .Ignore )
1418
+ val vfrom1 = GenFrom (makeTuple(allpats), rhs1, GenCheckMode .Ignore )
1423
1419
makeFor(mapName, flatMapName, vfrom1 :: rest1, body)
1424
1420
case (gen : GenFrom ) :: test :: rest =>
1425
1421
val filtered = Apply (rhsSelect(gen, nme.withFilter), makeLambda(gen, test))
@@ -1594,7 +1590,7 @@ object desugar {
1594
1590
* without duplicates
1595
1591
*/
1596
1592
private def getVariables (tree : Tree )(implicit ctx : Context ): List [VarInfo ] = {
1597
- val buf = new ListBuffer [VarInfo ]
1593
+ val buf = ListBuffer [VarInfo ]()
1598
1594
def seenName (name : Name ) = buf exists (_._1.name == name)
1599
1595
def add (named : NameTree , t : Tree ): Unit =
1600
1596
if (! seenName(named.name) && named.name.isTermName) buf += ((named, t))
0 commit comments