Skip to content

In enum with type parameter, can't call constructor for enum case with default argument #22137

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

Closed
joan38 opened this issue Dec 4, 2024 · 4 comments · Fixed by #22157
Closed
Assignees
Milestone

Comments

@joan38
Copy link
Contributor

joan38 commented Dec 4, 2024

Default parameters on enum cases does not seem to work properly.

Minimized code

enum Parser[+Value]:
  case Success(value: Value, issues: Seq[Failure] = Seq.empty) extends Parser[Value]
  case Failure(exception: Throwable)                           extends Parser[Nothing]

Parser.Success(1)
^
method $lessinit$greater$default$2 in object Success does not take type parameters

https://scastie.scala-lang.org/xZ81zFUkSECDcf2vpVgG1g

Workaround

enum Parser[+Value]:
  case Success[+Value](value: Value, issues: Seq[Failure] = Seq.empty) extends Parser[Value]
  case Failure(exception: Throwable)                                   extends Parser[Nothing]

Parser.Success(1)

https://scastie.scala-lang.org/avT9leMZRJmC0VMP14UeoA

@joan38 joan38 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 4, 2024
@SethTisue SethTisue changed the title enum with default for fields/parameters In enum with type parameter, can't call constructor for enum case with default argument Dec 4, 2024
@bishabosha
Copy link
Member

bishabosha commented Dec 4, 2024

wow I'm surprised no one tried this before (like me)

@joan38
Copy link
Contributor Author

joan38 commented Dec 18, 2024

Thanks @kasiaMarek and everyone. Amazing work!

@WojciechMazur WojciechMazur added this to the 3.6.4 milestone Jan 16, 2025
@joan38
Copy link
Contributor Author

joan38 commented Jan 30, 2025

Sounds like this one is not completely solved in 3.6.3:

enum Parser[+Value]:
  case Success(value: Value, issues: Seq[Failure] = Seq.empty)
  case Failure(exception: Throwable) extends Parser[Nothing]
Parser.Success(1)
^
method $lessinit$greater$default$2 in object Success does not take type parameters

But the following works:

Parser.Success(1), Seq.empty)

Thanks

@joan38
Copy link
Contributor Author

joan38 commented Jan 30, 2025

Sorry I just saw the fix will be released in 3.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants