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 @@ -161,15 +161,26 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
161
161
if (this .flags == flags) this
162
162
else copy(flags = flags)
163
163
164
- def withAddedMod (mod : Mod ): Modifiers =
165
- if (mods.exists(_ eq mod)) this
166
- else withMods(mods :+ mod)
164
+ def withAddedMod (mod : Mod ): Modifiers =
165
+ if (mods.exists(_ eq mod)) this
166
+ else withMods(mods :+ mod)
167
167
168
- def withMods (ms : List [Mod ]): Modifiers =
169
- if (mods eq ms) this
170
- else copy(mods = ms)
168
+ /** Modifiers with given list of Mods. It is checked that
169
+ * all modifiers are already accounted for in `flags` and `privateWithin`.
170
+ */
171
+ def withMods (ms : List [Mod ]): Modifiers = {
172
+ if (mods eq ms) this
173
+ else {
174
+ if (ms.nonEmpty)
175
+ for (m <- ms)
176
+ assert(flags.is(m.flags) ||
177
+ m.isInstanceOf [Mod .Private ] && ! privateWithin.isEmpty,
178
+ s " unaccounted modifier: $m in $this when adding $ms" )
179
+ copy(mods = ms)
180
+ }
181
+ }
171
182
172
- def withAddedAnnotation (annot : Tree ): Modifiers =
183
+ def withAddedAnnotation (annot : Tree ): Modifiers =
173
184
if (annotations.exists(_ eq annot)) this
174
185
else withAnnotations(annotations :+ annot)
175
186
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