Skip to content
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

-Wunused:all and private case class constructors #16675

Closed
amumurst opened this issue Jan 13, 2023 · 4 comments · Fixed by #16683
Closed

-Wunused:all and private case class constructors #16675

amumurst opened this issue Jan 13, 2023 · 4 comments · Fixed by #16683
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Milestone

Comments

@amumurst
Copy link

I tried adding the new unused flag (from #16157) to my work codebase and was surprised it hit places where private constructors were used to prevent creation of invalid case classes.

Compiler version

With nightly: 3.3.0-RC1-bin-20230112-be10bc6-NIGHTLY

Minimized code

//> using scala "3.3.0-RC1-bin-20230112-be10bc6-NIGHTLY"
//> using option "-Wunused:all"

case class PositiveNumber private (i: Int)
object PositiveNumber:
  def make(i: Int): Option[PositiveNumber] = 
    Option.when(i >= 0)(PositiveNumber(i))

PositiveNumber.make(1).foreach(n => println(n.i))

Output

[warn] ./unused-private-constructor.sc:4:1: unused private member
[warn] case class PositiveNumber private (i: Int)
[warn] ^
[warn] ./unused-private-constructor.sc:4:26: unused private member
[warn] case class PositiveNumber private (i: Int)
[warn]                          ^^^^
[warn] ./unused-private-constructor.sc:4:42: unused private member
[warn] case class PositiveNumber private (i: Int)
[warn]                                          ^

Expectation

I would expect that the autogenerated private methods of a case class were not warned about since I have no way of removing that warning as an end user.

@amumurst amumurst added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2023
@Kordyjan Kordyjan added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2023
@Kordyjan Kordyjan added this to the 3.3.0 backports milestone Jan 13, 2023
@Kordyjan Kordyjan assigned szymon-rd and unassigned szymon-rd Jan 13, 2023
@szymon-rd szymon-rd added regression This worked in a previous version but doesn't anymore and removed regression This worked in a previous version but doesn't anymore labels Jan 13, 2023
@szymon-rd
Copy link
Contributor

@PaulCoral could you take a look? Do you know what is causing this?

PaulCoral added a commit to PaulCoral/dotty that referenced this issue Jan 13, 2023
- Fix flag confusion between (case)accessor and (potentially) generated
  method in classes
- Update test suits. Add test from scala#16675
@PaulCoral
Copy link
Contributor

PaulCoral commented Jan 13, 2023

@szymon-rd I added a fix #16683. It seems like I have broken reporting of private constructor, while fixing param accessors.

@szymon-rd
Copy link
Contributor

@PaulCoral have you seen all the other issues? It seems that there are a lot of edge cases. We are running the open cb on with this flag now, maybe we will find more.

@PaulCoral
Copy link
Contributor

@szymon-rd Yes, I'm already on the next one.

szymon-rd added a commit that referenced this issue Jan 13, 2023
…, due to flags used to distinguish case accessors. (#16683)

@szymon-rd This fixes #16675. This add more flags checks on symbol to
distinguish generated method and various accessors generated by case
classes

### DONE
- Fix flag confusion between (case)accessor and (potentially) generated
method in classes
- Update test suits
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
- Fix flag confusion between (case)accessor and (potentially) generated
  method in classes
- Update test suits. Add test from scala#16675
@Kordyjan Kordyjan modified the milestones: 3.3.0 backports, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
4 participants