Skip to content

Fix #3900: add check for inline class parameters #3915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public enum ErrorMessageID {
UnableToEmitSwitchID,
MissingCompanionForStaticID,
PolymorphicMethodMissingTypeInParentID,
ParamsNoInlineID,
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
}
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ class Namer { typer: Typer =>
}
}

addAnnotations(denot.symbol, original)
addAnnotations(denot.symbol, original)

val selfInfo =
if (self.isEmpty) NoType
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i3900.scala
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/neg/inlinevals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down