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