@@ -164,25 +164,36 @@ trait QuotesAndSplices {
164164 case pt : TypeBounds => pt
165165 case _ => TypeBounds .empty
166166
167- def warnOnInferredBounds (typeSym : Symbol ) =
167+ def openQuote = if ctx.mode.is(Mode .QuotedExprPattern ) then " '{" else " '["
168+ def closeQuote = if ctx.mode.is(Mode .QuotedExprPattern ) then " }" else " ]"
169+
170+ def warnOnUnusedBounds (typeSym : Symbol ) =
168171 if ! (typeSymInfo =:= TypeBounds .empty) && ! (typeSym.info <:< typeSymInfo) then
169- val (openQuote, closeQuote) = if ctx.mode.is(Mode .QuotedExprPattern ) then (" '{" , " }" ) else (" '[" , " ]" )
170172 report.warning(em " Ignored bound $typeSymInfo\n\n Consider defining bounds explicitly: \n $openQuote $typeSym${typeSym.info & typeSymInfo}; ... $closeQuote" , tree.srcPos)
171173
174+ def warnOnInferredBounds (typeSym : Symbol ) =
175+ if ! (typeSymInfo =:= TypeBounds .empty) then
176+ if ctx.mode.is(Mode .QuotedExprPattern ) then // TODO drop this guard once SIP-53 is non-experimental
177+ // TODO state in the message when this will no longer work.
178+ // - We could stabilize SIP-53 and start deprecation warnings for type quoted patterns in 3.4.0.
179+ // - Then we could drop type variable inference 3.5.0.
180+ report.deprecationWarning(em " Type variable ` $tree` has partially inferred bounds $typeSymInfo. \n\n Consider defining bounds explicitly: \n $openQuote $typeSym$typeSymInfo; ... $closeQuote" , tree.srcPos)
181+
172182 getQuotedPatternTypeVariable(tree.name.asTypeName) match
173183 case Some (typeSym) =>
174184 checkExperimentalFeature(
175185 " support for multiple references to the same type (without backticks) in quoted type patterns (SIP-53)" ,
176186 tree.srcPos,
177187 " \n\n SIP-53: https://docs.scala-lang.org/sips/quote-pattern-type-variable-syntax.html" )
178- warnOnInferredBounds (typeSym)
188+ warnOnUnusedBounds (typeSym)
179189 ref(typeSym)
180190 case None =>
181191 val spliceContext = quotePatternSpliceContext
182192 val name = tree.name.toTypeName
183193 val nameOfSyntheticGiven = PatMatGivenVarName .fresh(tree.name.toTermName)
184194 val expr = untpd.cpy.Ident (tree)(nameOfSyntheticGiven)
185195 val typeSym = newSymbol(spliceContext.owner, name, EmptyFlags , typeSymInfo, NoSymbol , tree.span)
196+ warnOnInferredBounds(typeSym)
186197 typeSym.addAnnotation(Annotation (New (ref(defn.QuotedRuntimePatterns_patternTypeAnnot .typeRef)).withSpan(tree.span)))
187198 addQuotedPatternTypeVariable(typeSym)
188199 val pat = typedPattern(expr, defn.QuotedTypeClass .typeRef.appliedTo(typeSym.typeRef))(using spliceContext)
@@ -536,8 +547,12 @@ trait QuotesAndSplices {
536547object QuotesAndSplices {
537548 import tpd ._
538549
550+ private enum QuotePattenKind :
551+ case Expr , Type
552+
539553 /** Key for mapping from quoted pattern type variable names into their symbol */
540554 private val TypeVariableKey = new Property .Key [collection.mutable.Map [TypeName , Symbol ]]
555+ private val QuotePattenKindKey = new Property .Key [QuotePattenKind ]
541556
542557 /** Get the symbol for the quoted pattern type variable if it exists */
543558 def getQuotedPatternTypeVariable (name : TypeName )(using Context ): Option [Symbol ] =
0 commit comments