Skip to content

Commit 74c2954

Browse files
authored
Merge pull request #14425 from dwijnand/quote-matching-avoidance
2 parents 0647084 + fe6574c commit 74c2954

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -3056,8 +3056,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
30563056
// that we have found, seal them in a quoted.Type and add them to the result
30573057
def typeHoleApproximation(sym: Symbol) =
30583058
val fromAboveAnnot = sym.hasAnnotation(dotc.core.Symbols.defn.QuotedRuntimePatterns_fromAboveAnnot)
3059-
val approx = ctx1.gadt.approximation(sym, !fromAboveAnnot)
3060-
reflect.TypeReprMethods.asType(approx)
3059+
val fullBounds = ctx1.gadt.fullBounds(sym)
3060+
val tp = if fromAboveAnnot then fullBounds.hi else fullBounds.lo
3061+
reflect.TypeReprMethods.asType(tp)
30613062
matchings.map { tup =>
30623063
Tuple.fromIArray(typeHoles.map(typeHoleApproximation).toArray.asInstanceOf[IArray[Object]]) ++ tup
30633064
}

tests/pos-macros/i12343/Macro.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test
2+
3+
import scala.quoted.*
4+
5+
object Macro:
6+
def covImpl(arg: Expr[Any])(using Quotes): Expr[Any] = arg match // Covariant (List)
7+
case '{ $h : List[h] } => '{ $h : List[h] }
8+
9+
def invImpl(arg: Expr[Any])(using Quotes): Expr[Any] = arg match // Invariant (Set)
10+
case '{ $h : Set[h] } => '{ $h : Set[h] }
11+
12+
transparent inline def cov(inline arg: Any): Any = ${ covImpl('arg) }
13+
transparent inline def inv(inline arg: Any): Any = ${ invImpl('arg) }

tests/pos-macros/i12343/Test.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package test
2+
3+
object Test:
4+
val cov1: List[Boolean] = Macro.cov(List(true))
5+
val inv1: Set[Boolean] = Macro.inv(Set(true))
6+
def cov2[X](a: List[X]): List[X] = Macro.cov(a)
7+
def inv2[X](a: Set[X]): Set[X] = Macro.inv(a) // doesn't compile; Set[Nothing] is inferred

0 commit comments

Comments
 (0)