You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, recently in our project we encountered a bug with kittens derivation for a mid-size ADT that has 23 members (dangerously close to magical 24 number).
the project fails to compile with quite a lengthy error:
[error] Note: given instance mkCoproductInstances in object K0 was not considered because it was not imported with `import given`.
[error] enum MyADT derives Eq {
I made a couple of tests and found some interesting corellations.
When deriving Show instances we can only have 23 cases (without any fields!).
But for Eq typeclass we can have 27 cases (again without any fields).
However, if we add some fields to any of the cases, then each declared field will decrease the amount of possible cases by one starting from 23. In the presented case above we have 23 cases with and one field which does not compile. 22 cases in that example passes the compilation. Adding yet another field to the same case decrease the amount of possible cases.
Below does also not compile:
enumMyADTderivesEq {
caseA1caseA2caseA3caseA4caseA5caseA6caseA7caseA8caseA9caseA10caseA11caseA12caseA13caseA14caseA15caseA16caseA17// case A18// case A19// case A20// case A21// case A22caseAZ(foo: String, foo2: String, foo3: String, foo4: String, foo5: String)
}
It seems that it is not the overal amount of fields that matter, but the maximum amount in all cases.
Below is fine:
enumMyADTderivesEq {
caseA1(foo5: String)
caseA2(foo5: String)
caseA3(foo5: String)
caseA4(foo5: String)
caseA5caseA6caseA7caseA8caseA9caseA10caseA11caseA12caseA13caseA14caseA15caseA16caseA17// case A18// case A19// case A20// case A21// case A22caseAZ(foo: String, foo2: String, foo3: String, foo4: String)
}
scala version: 3.3.1
kittens: 3.2.0
Workaround
A possible workaround is to break such hierarchy into multiple ones, so in our first example that could be:
Hi, recently in our project we encountered a bug with kittens derivation for a mid-size ADT that has 23 members (dangerously close to magical 24 number).
Given the following code:
the project fails to compile with quite a lengthy error:
full error
scala-cli snippet here
I made a couple of tests and found some interesting corellations.
When deriving
Show
instances we can only have 23 cases (without any fields!).But for
Eq
typeclass we can have 27 cases (again without any fields).However, if we add some fields to any of the cases, then each declared field will decrease the amount of possible cases by one starting from 23. In the presented case above we have 23 cases with and one field which does not compile. 22 cases in that example passes the compilation. Adding yet another field to the same case decrease the amount of possible cases.
Below does also not compile:
It seems that it is not the overal amount of fields that matter, but the maximum amount in all cases.
Below is fine:
scala version: 3.3.1
kittens: 3.2.0
Workaround
A possible workaround is to break such hierarchy into multiple ones, so in our first example that could be:
which is obviously not ideal but it works.
The text was updated successfully, but these errors were encountered: