From a391f05b5e85fa02483dabd9fbe4fcc34f066fa7 Mon Sep 17 00:00:00 2001 From: Aleksander Rainko Date: Sat, 10 Jun 2023 05:51:44 +0200 Subject: [PATCH] fix: disallow `infix` objects Disallow `infix` objects by checking for the `infix` modifier in `Checking.scala`. Part of #17738 --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 ++ tests/neg/i17738-infix-object/NestedInfixObject.scala | 2 ++ tests/neg/i17738-infix-object/ToplevelInfixObject.scala | 1 + 3 files changed, 5 insertions(+) create mode 100644 tests/neg/i17738-infix-object/NestedInfixObject.scala create mode 100644 tests/neg/i17738-infix-object/ToplevelInfixObject.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 2869f64f33d0..305acea188da 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -584,6 +584,8 @@ object Checking { report.error(ModifierNotAllowedForDefinition(Sealed), flagSourcePos(Sealed)) if mods.is(Final, butNot = Synthetic) then report.warning(RedundantModifier(Final), flagSourcePos(Final)) + if mods.is(Infix) then + report.error(ModifierNotAllowedForDefinition(Infix), flagSourcePos(Infix)) /** Check the type signature of the symbol `M` defined by `tree` does not refer * to a private type or value which is invisible at a point where `M` is still diff --git a/tests/neg/i17738-infix-object/NestedInfixObject.scala b/tests/neg/i17738-infix-object/NestedInfixObject.scala new file mode 100644 index 000000000000..703cbef9e2ba --- /dev/null +++ b/tests/neg/i17738-infix-object/NestedInfixObject.scala @@ -0,0 +1,2 @@ +object ToplevelObject: + infix object NestedInfixObject // error diff --git a/tests/neg/i17738-infix-object/ToplevelInfixObject.scala b/tests/neg/i17738-infix-object/ToplevelInfixObject.scala new file mode 100644 index 000000000000..1ee13265b06c --- /dev/null +++ b/tests/neg/i17738-infix-object/ToplevelInfixObject.scala @@ -0,0 +1 @@ +infix object ToplevelInfixObject // error