Skip to content

Commit 467cbc7

Browse files
committed
Disallow inline secondary constructors
1 parent ea63740 commit 467cbc7

File tree

5 files changed

+11
-0
lines changed

5 files changed

+11
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ object Inliner {
9797
if tree.symbol.isExperimental then
9898
Feature.checkExperimentalDef(tree.symbol, tree)
9999

100+
if tree.symbol.isConstructor then return tree // error already reported for the inline constructor definition
101+
100102
/** Set the position of all trees logically contained in the expansion of
101103
* inlined call `call` to the position of `call`. This transform is necessary
102104
* when lifting bindings from the expansion to the outside of the call.

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,8 @@ class Typer extends Namer
21642164
PrepareInlineable.registerInlineInfo(sym, rhsToInline)
21652165

21662166
if sym.isConstructor then
2167+
if sym.is(Inline) then
2168+
report.error("constructors cannot be `inline`", ddef)
21672169
if sym.isPrimaryConstructor then
21682170
if sym.owner.is(Case) then
21692171
for

tests/neg/i12986a/Bar.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Bar(i: Int):
2+
inline def this() = this(0) // error

tests/neg/i12986a/Test.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val bar = new Bar()

tests/neg/i12986b.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Bar(i: Int):
2+
transparent inline def this() = this(0) // error
3+
4+
val bar = Bar()

0 commit comments

Comments
 (0)