From d9b8da5413cc564d7363024165957325d4b6893a Mon Sep 17 00:00:00 2001 From: HarrisL2 Date: Mon, 11 Nov 2024 11:17:36 -0500 Subject: [PATCH] Check for open flag on objects Fixes #21760 --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 ++ tests/neg/i21760.scala | 1 + 2 files changed, 3 insertions(+) create mode 100644 tests/neg/i21760.scala 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