-
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.
Backport "Refine handling of StaleSymbol type errors" to LTS (#20898)
Backports #19605 to the LTS branch. PR submitted by the release tooling.
- Loading branch information
Showing
5 changed files
with
79 additions
and
5 deletions.
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,11 @@ | ||
// ZSet.scala | ||
// moving it to core.scala would lead to Recursion limit exceeded: find-member prelude.ZSetSyntax | ||
package prelude | ||
|
||
import prelude.newtypes._ | ||
|
||
class ZSet[+A, +B] | ||
object ZSet | ||
trait ZSetSyntax { | ||
implicit final class ZSetMapOps[+A](self: Map[A, Natural]) | ||
} |
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,37 @@ | ||
// core.scala | ||
package prelude | ||
|
||
sealed trait Assertion[-A] | ||
object Assertion: | ||
def greaterThanOrEqualTo[A](value: A): Assertion[A] = ??? | ||
|
||
sealed trait AssertionError | ||
|
||
abstract class NewtypeCustom[A] { | ||
type Type | ||
protected inline def validateInline(inline value: A): Unit | ||
|
||
inline def apply(inline a1: A): Type = { | ||
validateInline(a1) | ||
a1.asInstanceOf[Type] | ||
} | ||
} | ||
abstract class Newtype[A] extends NewtypeCustom[A] { | ||
def assertion: Assertion[A] = ??? | ||
protected inline def validateInline(inline value: A): Unit = ${ | ||
Macros.validateInlineImpl[A]('assertion, 'value) | ||
} | ||
} | ||
|
||
abstract class Subtype[A] extends Newtype[A] { | ||
type Type <: A | ||
} | ||
|
||
|
||
package object newtypes { | ||
type Natural = Natural.Type | ||
object Natural extends Subtype[Int] { | ||
override inline def assertion = Assertion.greaterThanOrEqualTo(0) | ||
val one: Natural = Natural(1) // triggers macro | ||
} | ||
} |
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 @@ | ||
// macro.scala | ||
package prelude | ||
import scala.quoted.* | ||
|
||
object Macros { | ||
def validateInlineImpl[A: Type](assertionExpr: Expr[Assertion[A]], a: Expr[A])(using Quotes): Expr[Unit] = | ||
'{ () } | ||
} |
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 @@ | ||
// prelude.scala | ||
|
||
import prelude.newtypes.Natural | ||
|
||
package object prelude extends ZSetSyntax { | ||
type MultiSet[+A] = ZSet[A, Natural] | ||
val MultiSet: ZSet.type = ZSet | ||
} |