Skip to content

Commit 3db1783

Browse files
committed
Fix crashes
Unlike in Parsers, at this point in Desugar we get Synthetic objects. We also get objects with flags but without corresponding mods; they might all be synthetic, but let's harden flagPos anyway.
1 parent fd76897 commit 3db1783

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,14 @@ object desugar {
701701
val mods = mdef.mods
702702
def isEnumCase = mods.isEnumCase
703703

704-
def flagPos(flag: FlagSet) = mods.mods.find(_.flags == flag).get.pos
704+
def flagPos(flag: FlagSet) = mods.mods.find(_.flags == flag).fold(mdef.pos)(_.pos)
705705

706706
if (mods.is(Abstract))
707707
ctx.error(hl"""$Abstract modifier cannot be used for objects""", flagPos(Abstract))
708708
if (mods.is(Sealed))
709709
ctx.error(hl"""$Sealed modifier is redundant for objects""", flagPos(Sealed))
710710
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
711-
if (mods.is(Final))
711+
if (mods.is(Final) && !mods.is(Synthetic))
712712
ctx.warning(hl"""$Final modifier is redundant for objects""", flagPos(Final))
713713

714714
if (mods is Package)

0 commit comments

Comments
 (0)