diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 700bd483ff38..761e7cdab37c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -611,6 +611,8 @@ object Checking { val mods = mdef.mods def flagSourcePos(flag: FlagSet) = mods.mods.find(_.flags == flag).getOrElse(mdef).srcPos + if mods.is(Open) then + report.error(ModifierNotAllowedForDefinition(Open), flagSourcePos(Open)) if mods.is(Abstract) then report.error(ModifierNotAllowedForDefinition(Abstract), flagSourcePos(Abstract)) if mods.is(Sealed) then diff --git a/tests/neg/i21760.scala b/tests/neg/i21760.scala new file mode 100644 index 000000000000..625e03520dfb --- /dev/null +++ b/tests/neg/i21760.scala @@ -0,0 +1 @@ +open object O // error \ No newline at end of file