Skip to content

Commit

Permalink
Disallow inline secondary constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
prolativ committed Aug 24, 2021
1 parent ea63740 commit 467cbc7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ object Inliner {
if tree.symbol.isExperimental then
Feature.checkExperimentalDef(tree.symbol, tree)

if tree.symbol.isConstructor then return tree // error already reported for the inline constructor definition

/** Set the position of all trees logically contained in the expansion of
* inlined call `call` to the position of `call`. This transform is necessary
* when lifting bindings from the expansion to the outside of the call.
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,8 @@ class Typer extends Namer
PrepareInlineable.registerInlineInfo(sym, rhsToInline)

if sym.isConstructor then
if sym.is(Inline) then
report.error("constructors cannot be `inline`", ddef)
if sym.isPrimaryConstructor then
if sym.owner.is(Case) then
for
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i12986a/Bar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Bar(i: Int):
inline def this() = this(0) // error
1 change: 1 addition & 0 deletions tests/neg/i12986a/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val bar = new Bar()
4 changes: 4 additions & 0 deletions tests/neg/i12986b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Bar(i: Int):
transparent inline def this() = this(0) // error

val bar = Bar()

0 comments on commit 467cbc7

Please sign in to comment.