Skip to content

Commit

Permalink
Merge pull request #13370 from prolativ/disallow-inline-secondary-con…
Browse files Browse the repository at this point in the history
…structors

Disallow inline secondary constructors
  • Loading branch information
prolativ authored Aug 24, 2021
2 parents 4cfd8fe + 467cbc7 commit 62501c9
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 62501c9

Please sign in to comment.