From 138f834f76da259760b635813d9ab071137ed74a Mon Sep 17 00:00:00 2001
From: Dale Wijnand <dale.wijnand@gmail.com>
Date: Mon, 7 Feb 2022 11:04:25 +0000
Subject: [PATCH] Fix invariant quote type holes

---
 compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
index ae3067a894d7..000f84199c27 100644
--- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
+++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
@@ -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
       }