@@ -164,25 +164,36 @@ trait QuotesAndSplices {
164
164
case pt : TypeBounds => pt
165
165
case _ => TypeBounds .empty
166
166
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 ) =
168
171
if ! (typeSymInfo =:= TypeBounds .empty) && ! (typeSym.info <:< typeSymInfo) then
169
- val (openQuote, closeQuote) = if ctx.mode.is(Mode .QuotedExprPattern ) then (" '{" , " }" ) else (" '[" , " ]" )
170
172
report.warning(em " Ignored bound $typeSymInfo\n\n Consider defining bounds explicitly: \n $openQuote $typeSym${typeSym.info & typeSymInfo}; ... $closeQuote" , tree.srcPos)
171
173
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
+
172
182
getQuotedPatternTypeVariable(tree.name.asTypeName) match
173
183
case Some (typeSym) =>
174
184
checkExperimentalFeature(
175
185
" support for multiple references to the same type (without backticks) in quoted type patterns (SIP-53)" ,
176
186
tree.srcPos,
177
187
" \n\n SIP-53: https://docs.scala-lang.org/sips/quote-pattern-type-variable-syntax.html" )
178
- warnOnInferredBounds (typeSym)
188
+ warnOnUnusedBounds (typeSym)
179
189
ref(typeSym)
180
190
case None =>
181
191
val spliceContext = quotePatternSpliceContext
182
192
val name = tree.name.toTypeName
183
193
val nameOfSyntheticGiven = PatMatGivenVarName .fresh(tree.name.toTermName)
184
194
val expr = untpd.cpy.Ident (tree)(nameOfSyntheticGiven)
185
195
val typeSym = newSymbol(spliceContext.owner, name, EmptyFlags , typeSymInfo, NoSymbol , tree.span)
196
+ warnOnInferredBounds(typeSym)
186
197
typeSym.addAnnotation(Annotation (New (ref(defn.QuotedRuntimePatterns_patternTypeAnnot .typeRef)).withSpan(tree.span)))
187
198
addQuotedPatternTypeVariable(typeSym)
188
199
val pat = typedPattern(expr, defn.QuotedTypeClass .typeRef.appliedTo(typeSym.typeRef))(using spliceContext)
@@ -536,8 +547,12 @@ trait QuotesAndSplices {
536
547
object QuotesAndSplices {
537
548
import tpd ._
538
549
550
+ private enum QuotePattenKind :
551
+ case Expr , Type
552
+
539
553
/** Key for mapping from quoted pattern type variable names into their symbol */
540
554
private val TypeVariableKey = new Property .Key [collection.mutable.Map [TypeName , Symbol ]]
555
+ private val QuotePattenKindKey = new Property .Key [QuotePattenKind ]
541
556
542
557
/** Get the symbol for the quoted pattern type variable if it exists */
543
558
def getQuotedPatternTypeVariable (name : TypeName )(using Context ): Option [Symbol ] =
0 commit comments