diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index c20fc27f9d1a..8cc9fc1fc63f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -125,6 +125,7 @@ public enum ErrorMessageID { UnableToEmitSwitchID, MissingCompanionForStaticID, PolymorphicMethodMissingTypeInParentID, + ParamsNoInlineID, ; public int errorNumber() { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index c0f1dd20d5fb..f9f75a7d4882 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -2069,4 +2069,11 @@ object messages { |$rsym does not override any method in $parentSym. Structural refinement does not allow for |polymorphic methods.""" } + + case class ParamsNoInline(owner: Symbol)(implicit ctx: Context) + extends Message(ParamsNoInlineID) { + val kind = "Syntax" + val msg = hl"""${"inline"} modifier cannot be used for a ${owner.showKind} parameter""" + val explanation = "" + } } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 85343fb1ef65..9a9e196000ad 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -341,6 +341,9 @@ object Checking { if (!ok && !sym.is(Synthetic)) fail(i"modifier `$flag` is not allowed for this definition") + if (sym.is(Inline) && ((sym.is(ParamAccessor) && sym.owner.isClass) || sym.is(TermParam) && sym.owner.isClassConstructor)) + fail(ParamsNoInline(sym.owner)) + if (sym.is(ImplicitCommon)) { if (sym.owner.is(Package)) fail(TopLevelCantBeImplicit(sym)) diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index e770d2c615f3..12868360ff52 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -925,7 +925,7 @@ class Namer { typer: Typer => } } - addAnnotations(denot.symbol, original) + addAnnotations(denot.symbol, original) val selfInfo = if (self.isEmpty) NoType diff --git a/tests/neg/i3900.scala b/tests/neg/i3900.scala new file mode 100644 index 000000000000..c64bd6bca71b --- /dev/null +++ b/tests/neg/i3900.scala @@ -0,0 +1,7 @@ +class Foo(inline val i: Int) // error +case class Foo2(inline val i: Int) // error +class Foo3(inline val i: Int) extends AnyVal // error +trait Foo4(inline val i: Int) // error +class Foo5() { + def this(inline x: Int) = this() // error +} diff --git a/tests/neg/inlinevals.scala b/tests/neg/inlinevals.scala index d7d45e248a74..6c8c4eaf6327 100644 --- a/tests/neg/inlinevals.scala +++ b/tests/neg/inlinevals.scala @@ -7,7 +7,7 @@ object Test { inline inline val twice = 30 // error: repeated modifier - class C(inline x: Int, private inline val y: Int) { + class C(inline x: Int, private inline val y: Int) { // error // error inline val foo: Int // error: abstract member may not be inline inline def bar: Int // error: abstract member may not be inline }