Skip to content

Disallow case classes defined in inline methods #11165

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

Conversation

nicolasstucki
Copy link
Contributor

The motivations are

  • Disallow code that looks inoffensive small but has a large code size impact when inlined. We can still implement the same but must be explicit. Or implement those case classes outside of the method and avoid duplication.
  • Simplify implementation of Expand non-transparent macros after Typer #9984

@nicolasstucki nicolasstucki force-pushed the disallow-case-classes-in-inlined-code branch from 91f969e to a4622ae Compare January 19, 2021 16:04
@nicolasstucki nicolasstucki force-pushed the disallow-case-classes-in-inlined-code branch from a4622ae to 15c4964 Compare January 19, 2021 16:06
@nicolasstucki nicolasstucki marked this pull request as ready for review January 20, 2021 08:53
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM


case tree: TypeDef if tree.symbol.is(Case) && level > 0 =>
report.error(reporting.CaseClassInInlinedCode(tree), tree)
super.transform(tree)
Copy link
Contributor

Choose a reason for hiding this comment

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

Case classes are just desugarings. Maybe generalize it to all TypeDef?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by generalizing? Do you mean not allowing these ones?

'{ class Bar extends Foo { def foo = ... }; ... }
'{ type T = ...;  }

Those are necessary.

Copy link
Contributor

@liufengyun liufengyun Jan 20, 2021

Choose a reason for hiding this comment

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

If we don't generalize, the rule seems arbitrary and will not do the job. If a programmer just hand-crafted the desugaring of a case class, doesn't it have the same effect as a case class?

@nicolasstucki nicolasstucki merged commit e10cfa8 into scala:master Jan 20, 2021
@nicolasstucki nicolasstucki deleted the disallow-case-classes-in-inlined-code branch January 20, 2021 11:45
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

3 participants