File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -163,15 +163,26 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
163
163
if (this .flags == flags) this
164
164
else copy(flags = flags)
165
165
166
- def withAddedMod (mod : Mod ): Modifiers =
167
- if (mods.exists(_ eq mod)) this
168
- else withMods(mods :+ mod)
166
+ def withAddedMod (mod : Mod ): Modifiers =
167
+ if (mods.exists(_ eq mod)) this
168
+ else withMods(mods :+ mod)
169
169
170
- def withMods (ms : List [Mod ]): Modifiers =
171
- if (mods eq ms) this
172
- else copy(mods = ms)
170
+ /** Modifiers with given list of Mods. It is checked that
171
+ * all modifiers are already accounted for in `flags` and `privateWithin`.
172
+ */
173
+ def withMods (ms : List [Mod ]): Modifiers = {
174
+ if (mods eq ms) this
175
+ else {
176
+ if (ms.nonEmpty)
177
+ for (m <- ms)
178
+ assert(flags.is(m.flags) ||
179
+ m.isInstanceOf [Mod .Private ] && ! privateWithin.isEmpty,
180
+ s " unaccounted modifier: $m in $this when adding $ms" )
181
+ copy(mods = ms)
182
+ }
183
+ }
173
184
174
- def withAddedAnnotation (annot : Tree ): Modifiers =
185
+ def withAddedAnnotation (annot : Tree ): Modifiers =
175
186
if (annotations.exists(_ eq annot)) this
176
187
else withAnnotations(annotations :+ annot)
177
188
Original file line number Diff line number Diff line change @@ -2270,7 +2270,7 @@ object Parsers {
2270
2270
/** EnumCase = `case' (id ClassConstr [`extends' ConstrApps] | ids)
2271
2271
*/
2272
2272
def enumCase (start : Offset , mods : Modifiers ): DefTree = {
2273
- val mods1 = mods.withAddedMod( atPos(in.offset)(Mod .Enum ())) | Case
2273
+ val mods1 = addMod(mods, atPos(in.offset)(Mod .Enum ())) | Case
2274
2274
accept(CASE )
2275
2275
2276
2276
in.adjustSepRegions(ARROW )
You can’t perform that action at this time.
0 commit comments