Skip to content

Disallow inline secondary constructors #13370

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
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
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()