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