-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a -3.6-migration warning for opaque select changes
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Migration Warning: tests/warn/i21239.Frac.scala:14:8 ---------------------------------------------------------------- | ||
14 | f + Frac.wrap(((-g.numerator).toLong << 32) | (g.unwrap & 0xFFFFFFFFL)) // warn | ||
| ^^^ | ||
| Previously this selected the extension method + in object Frac | ||
| Now it selects + on the opaque type's underlying type Long | ||
| | ||
| You can change this back by selecting kse.maths.Frac.+(f) | ||
| Or by defining the extension method outside of the opaque type's scope. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kse.maths | ||
|
||
import scala.language.`3.6-migration` | ||
|
||
opaque type Frac = Long | ||
object Frac { | ||
inline def wrap(f: Long): kse.maths.Frac = f | ||
extension (f: Frac) | ||
inline def unwrap: Long = f | ||
inline def numerator: Int = ((f: Long) >>> 32).toInt | ||
extension (f: kse.maths.Frac) | ||
def +(g: Frac): kse.maths.Frac = f // eliding domain-specific addition logic | ||
def -(g: Frac): kse.maths.Frac = | ||
f + Frac.wrap(((-g.numerator).toLong << 32) | (g.unwrap & 0xFFFFFFFFL)) // warn | ||
} |