Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3056,8 +3056,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
// that we have found, seal them in a quoted.Type and add them to the result
def typeHoleApproximation(sym: Symbol) =
val fromAboveAnnot = sym.hasAnnotation(dotc.core.Symbols.defn.QuotedRuntimePatterns_fromAboveAnnot)
val approx = ctx1.gadt.approximation(sym, !fromAboveAnnot)
reflect.TypeReprMethods.asType(approx)
val fullBounds = ctx1.gadt.fullBounds(sym)
val tp = if fromAboveAnnot then fullBounds.hi else fullBounds.lo
reflect.TypeReprMethods.asType(tp)
matchings.map { tup =>
Tuple.fromIArray(typeHoles.map(typeHoleApproximation).toArray.asInstanceOf[IArray[Object]]) ++ tup
}
Expand Down
13 changes: 13 additions & 0 deletions tests/pos-macros/i12343/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test

import scala.quoted.*

object Macro:
def covImpl(arg: Expr[Any])(using Quotes): Expr[Any] = arg match // Covariant (List)
case '{ $h : List[h] } => '{ $h : List[h] }

def invImpl(arg: Expr[Any])(using Quotes): Expr[Any] = arg match // Invariant (Set)
case '{ $h : Set[h] } => '{ $h : Set[h] }

transparent inline def cov(inline arg: Any): Any = ${ covImpl('arg) }
transparent inline def inv(inline arg: Any): Any = ${ invImpl('arg) }
7 changes: 7 additions & 0 deletions tests/pos-macros/i12343/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test

object Test:
val cov1: List[Boolean] = Macro.cov(List(true))
val inv1: Set[Boolean] = Macro.inv(Set(true))
def cov2[X](a: List[X]): List[X] = Macro.cov(a)
def inv2[X](a: Set[X]): Set[X] = Macro.inv(a) // doesn't compile; Set[Nothing] is inferred