Skip to content

Conversation

@hamzaremmal
Copy link
Member

Closes #24681

if sym.is(Inline) then
report.error("constructors cannot be `inline`", ddef)

if sym.targetName != sym.name then
Copy link
Member Author

Choose a reason for hiding this comment

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

Just for the record: Technically, if the specification says (for #22372) we are not allowed to use @targetName on constructors, then this check (that was already present) doesn't encode that specification since we can always write this example below and it will work:

import scala.annotation.targetName

class Foo @targetName("<init>") ()

@hamzaremmal hamzaremmal enabled auto-merge December 6, 2025 12:30
Copy link
Member

@mbovel mbovel left a comment

Choose a reason for hiding this comment

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

This check was introduced in #7726 (found with git log -L 3121,3136:compiler/src/dotty/tools/dotc/typer/Typer.scala).
As far as I can tell, it was indeed meant to apply to any constructor.

@hamzaremmal hamzaremmal merged commit 68396ca into scala:main Dec 6, 2025
85 of 86 checks passed
@hamzaremmal hamzaremmal deleted the i24681 branch December 6, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@targetName is only checked in non-primary constructors

2 participants