Iltotore / iron

Strong type constraints for Scala
https://iltotore.github.io/iron/docs/
Apache License 2.0
457 stars 43 forks source link

IronCats: Ambiguous given instances #160

Closed agregoris closed 1 year ago

agregoris commented 1 year ago

Describe the bug Scala environment: JVM Scala version: 3.3.0 Iron version: 2.2.0

Reproduction steps The steps to reproduce the described issue

Expected behavior I expect it compiles

Current behavior I found this error:

[error] 185 |object CustomDataMap extends Newtype[Map[String, String] :| MaxLength[5]]
[error]     |                                                                         ^
[error]     |Ambiguous given instances: both given instance given_Eq_:| in trait IronCatsInstances and given instance given_Hash_:| in trait IronCatsLowPriority match type cats.kernel.Eq[
[error]     |  io.github.iltotore.iron.IronType[Map[String, String],
[error]     |    io.github.iltotore.iron.constraint.collection.MaxLength[(5 : Int)]]
[error]     |] of parameter eqv of constructor Newtype in class Newtype
Iltotore commented 1 year ago

Seems to be a change in implicit resolution between Scala 3.3 and 3.2. Does it work in 3.2?

Can you send the full code?

agregoris commented 1 year ago

I've left a simplified example of the error in Scastie https://scastie.scala-lang.org/AtAtGZYFRViT42d2mtZtag

It also fails in Scala 3.2.2

Iltotore commented 1 year ago

I think I will be able to investigate this issue this week. Also, why don't you use the RefinedTypeOps trait? For instance: https://scastie.scala-lang.org/3xI1FuCjRKy4VcLr0cw5RA

Iltotore commented 1 year ago

@agregoris I pushed the fix to the main branch. The snapshot should be available on Sonatype tomorrow.