File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,35 @@ This will output all parameters explicitly:
138138...
139139```
140140
141+ ### Explicit Prioritization by Owner
142+
143+ One effective way to ensure that the most specific given instance is
144+ selected -— particularly useful when migrating libraries to Scala 3.5 -—
145+ is to leverage the inheritance rules as outlined in point 8 of [ the
146+ language
147+ reference] ( https://docs.scala-lang.org/scala3/reference/changed-features/implicit-resolution.html ) :
148+
149+ ``` scala
150+ class General
151+ class Specific extends General
152+
153+ class LowPriority :
154+ given a : General ()
155+
156+ object NormalPriority extends LowPriority :
157+ given b : Specific ()
158+
159+ def run =
160+ import NormalPriority .given
161+ val x = summon[General ]
162+ val _: Specific = x // <- b was picked
163+ ```
164+
165+ The idea is to enforce prioritization through the inheritance
166+ hierarchies of classes that provide ` given ` instances. By importing the
167+ ` given ` instances from the object with the highest priority, you can
168+ control which instance is selected by the compiler.
169+
141170### Outlook
142171
143172We are considering adding ` -rewrite ` rules that automatically insert
You can’t perform that action at this time.
0 commit comments