Skip to content

Fix #2421: Add errors for inline on non supported trees #2476

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
Jul 16, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ object Checking {
fail(AbstractMemberMayNotHaveModifier(sym, flag))
def checkNoConflict(flag1: FlagSet, flag2: FlagSet) =
if (sym.is(allOf(flag1, flag2)))
fail(i"illegal combination of modifiers: $flag1 and $flag2 for: $sym")
fail(i"illegal combination of modifiers: `$flag1` and `$flag2` for: $sym")
def checkApplicable(flag: FlagSet, ok: Boolean) =
if (!ok && !sym.is(Synthetic))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the !sym.is(Synthetic) needed here? Is it only for the lazy val of the modules?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now yes, but there might be other synthetic symbols with conflicts. In any case, if it is synthetic we should not issue an error message to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fail(i"modifier `$flag` is not allowed for this definition")

if (sym.is(ImplicitCommon)) {
if (sym.owner.is(Package))
Expand Down Expand Up @@ -345,6 +348,9 @@ object Checking {
checkNoConflict(Final, Sealed)
checkNoConflict(Private, Protected)
checkNoConflict(Abstract, Override)
checkNoConflict(Lazy, Inline)
if (sym.is(Inline)) checkApplicable(Inline, sym.isTerm && !sym.is(Mutable | Module))
if (sym.is(Lazy)) checkApplicable(Lazy, !sym.is(Method | Mutable))
if (sym.isType && !sym.is(Deferred))
for (cls <- sym.allOverriddenSymbols.filter(_.isClass)) {
fail(CannotHaveSameNameAs(sym, cls, CannotHaveSameNameAs.CannotBeOverridden))
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ class Namer { typer: Typer =>
def privateWithinClass(mods: Modifiers) =
enclosingClassNamed(mods.privateWithin, mods.pos)

/** Check that flags are OK for symbol. This is done early to avoid
* catastrophic failure when we create a TermSymbol with TypeFlags, or vice versa.
* A more complete check is done in checkWellformed.
*/
def checkFlags(flags: FlagSet) =
if (flags.isEmpty) flags
else {
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i2421.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
inline object Foo // error: modifier(s) `inline' incompatible with type definition
inline class Bar // error: modifier(s) `inline' incompatible with type definition
inline abstract class Baz // error: modifier(s) `inline' incompatible with type definition
inline trait Qux // error: modifier(s) `inline' incompatible with type definition

object Quux {
inline type T // error: modifier(s) `inline' incompatible with type definition
inline var x: Int = 42 // error: modifier(s) `inline' incompatible with var definition
inline lazy val y: Int = 43 // error: modifier(s) `inline' incompatible with lazy val definition
}
12 changes: 12 additions & 0 deletions tests/neg/i2712.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Foo {
lazy var x: Int = 42 // error: modifier(s) `lazy' incompatible with var definition
lazy def y: Int = 42 // error: modifier(s) `lazy' incompatible with def definition
}

lazy class Bar // error: modifier(s) `lazy' incompatible with type definition
lazy abstract class Baz // error: modifier(s) `lazy abstract' incompatible with type definition
lazy trait Qux // error: modifier(s) `lazy' not allowed for trait

object Quux {
lazy type T // error: modifier(s) `lazy' incompatible with type definition
}