-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hash code of ExprImpl and TypeImpl
Fixes #15227
- Loading branch information
1 parent
9d68778
commit c6b89d4
Showing
6 changed files
with
50 additions
and
0 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
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 @@ | ||
import scala.quoted.* | ||
|
||
inline def mac[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using Quotes): Expr[T] = { | ||
import quotes.reflect.* | ||
val expr2 = expr.asTerm.asExpr | ||
|
||
assert(expr == expr2) | ||
assert(expr.hashCode() == expr2.hashCode()) | ||
|
||
expr | ||
|
||
} |
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,2 @@ | ||
@main def test = | ||
mac(1) |
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,27 @@ | ||
import scala.quoted.* | ||
|
||
inline def mac[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
class MyMap() extends ExprMap { | ||
var expressions: List[Expr[Any]] = Nil | ||
|
||
override def transform[T](e: Expr[T])(using Type[T])(using q: Quotes): Expr[T] = | ||
expressions ::= e | ||
transformChildren(e) | ||
|
||
} | ||
|
||
def impl[T: Type](expr: Expr[T])(using Quotes): Expr[T] = { | ||
|
||
val List(es1, es2) = List(MyMap(), MyMap()).map { m => | ||
m.transform(expr) | ||
m.expressions | ||
} | ||
|
||
assert(es1 == es2) | ||
assert(es1.map(_.hashCode()) == es2.map(_.hashCode()), s"hash codes not equal:\n${es1.map(_.hashCode())}\n${es2.map(_.hashCode())}") | ||
|
||
expr | ||
|
||
} |
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,2 @@ | ||
@main def test = | ||
mac(1) |