From da7a8cb777da3575e98945570a684d9a331844ee Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Thu, 25 Jan 2018 14:07:35 +0100 Subject: [PATCH 1/3] Fix #3900: add check for inline class parameters --- .../tools/dotc/reporting/diagnostic/ErrorMessageID.java | 1 + .../dotty/tools/dotc/reporting/diagnostic/messages.scala | 7 +++++++ compiler/src/dotty/tools/dotc/typer/Checking.scala | 3 +++ compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 +- tests/neg/i3900.scala | 4 ++++ 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i3900.scala 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..739bc263fa61 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) + 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..ed859cd17657 --- /dev/null +++ b/tests/neg/i3900.scala @@ -0,0 +1,4 @@ +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 From 1cfea91f70acf20a7bdaf3f13244cd9078aa4eed Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Thu, 25 Jan 2018 16:54:08 +0100 Subject: [PATCH 2/3] Update inlinevals neg test with the missing errors --- tests/neg/inlinevals.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 10a3a08ddf6aa1c8b46f94bc74328e11c9d580de Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Fri, 26 Jan 2018 13:44:57 +0100 Subject: [PATCH 3/3] Update check for secondary constructors --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 +- tests/neg/i3900.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 739bc263fa61..9a9e196000ad 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -341,7 +341,7 @@ 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) + if (sym.is(Inline) && ((sym.is(ParamAccessor) && sym.owner.isClass) || sym.is(TermParam) && sym.owner.isClassConstructor)) fail(ParamsNoInline(sym.owner)) if (sym.is(ImplicitCommon)) { diff --git a/tests/neg/i3900.scala b/tests/neg/i3900.scala index ed859cd17657..c64bd6bca71b 100644 --- a/tests/neg/i3900.scala +++ b/tests/neg/i3900.scala @@ -2,3 +2,6 @@ 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 +}