-
Notifications
You must be signed in to change notification settings - Fork 44
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
fix: Ambiguous given instance inside RefinedTypeOps
#180
Conversation
This should work (waiting for the nightly version) but perhaps it would be better to grant access to the given instance (to avoid re-synthesis)? |
If we do that, the given instance would leak. For example, this code would compile: import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.Positive
opaque type Temperature = Int :| Positive
object Temperature extends RefinedTypeOps[Int, Positive, Temperature] //No explicit iron import
import foo.Temperature
summon[RuntimeConstraint[Int, Positive]] //Works which is not the expected behaviour. Also I'm afraid this would cause other ambiguous given errors: opaque type Temperature = Int :| Positive
object Temperature extends RefinedTypeOps[Int, Positive, Temperature]
opaque type Moisture= Int :| Positive
object Moisture extends RefinedTypeOps[Int, Positive, Moisture] import foo.{Moisture, Temperature}
summon[RuntimeConstraint[Int, Positive]] //Ambiguous given errors: both Moisture.rtc and Temperature.rtc are eligible
the inline def does not re-synthetize nor add any overhead on top of the protected given |
I am using I think |
From the workaround in the ticket, type IsWhole = GreaterEqual[0]
opaque type Whole <: Int = Int :| IsWhole
object Whole extends RefinedTypeOps[Int, IsWhole, Whole]:
given Parse[Whole] =
summon[Parse[Int]].refineParse(using rtc) I would like to avoid having to specify the given instance ( given Parse[Whole] =
summon[Parse[Int]].refineParse |
You shouldn't have to. That's why the |
This code compiles with this PR: import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.numeric.GreaterEqual
trait Parse[A]:
def refineParse[C](using contraint: RuntimeConstraint[A, C]): Parse[A :| C] = ???
given Parse[Int] = new Parse[Int]{}
type IsWhole = GreaterEqual[0]
opaque type Whole <: Int = Int :| IsWhole
object Whole extends RefinedTypeOps[Int, IsWhole, Whole]:
given Parse[Whole] = summon[Parse[Int]].refineParse |
Thanks for checking. I was getting compiler errors (something about deferred inline) with |
No problem. Feel free to open a new discussion or issue if you have hard time dealing with this error. |
Closes #178
@ajaychandran can you check if this PR solves your problem?