@@ -199,10 +199,10 @@ trait QuotesAndSplices {
199
199
* )
200
200
* ```
201
201
*/
202
- private def splitQuotePattern (quoted : Tree )(using Context ): (Map [Symbol , Bind ], Tree , List [Tree ]) = {
202
+ private def splitQuotePattern (quoted : Tree )(using Context ): (collection. Map [Symbol , Bind ], Tree , List [Tree ]) = {
203
203
val ctx0 = ctx
204
204
205
- val typeBindings : collection. mutable.Map [Symbol , Bind ] = collection. mutable.Map .empty
205
+ val typeBindings : mutable.Map [Symbol , Bind ] = mutable.LinkedHashMap .empty
206
206
def getBinding (sym : Symbol ): Bind =
207
207
typeBindings.getOrElseUpdate(sym, {
208
208
val bindingBounds = sym.info
@@ -296,13 +296,19 @@ trait QuotesAndSplices {
296
296
}
297
297
}
298
298
val shape0 = splitter.transform(quoted)
299
- val patterns = (splitter.freshTypePatBuf .iterator ++ splitter.typePatBuf .iterator ++ splitter.patBuf.iterator).toList
299
+ val patterns = (splitter.typePatBuf .iterator ++ splitter.freshTypePatBuf .iterator ++ splitter.patBuf.iterator).toList
300
300
val freshTypeBindings = splitter.freshTypeBindingsBuff.result()
301
301
302
- val shape1 = seq(
303
- freshTypeBindings,
304
- shape0
305
- )
302
+ val shape1 = shape0 match
303
+ case Block (stats @ ((tdef : TypeDef ) :: rest), expr) if tdef.symbol.hasAnnotation(defn.QuotedRuntimePatterns_patternTypeAnnot ) =>
304
+ val (bindings, otherStats) = stats.span {
305
+ case tdef : TypeDef => tdef.symbol.hasAnnotation(defn.QuotedRuntimePatterns_patternTypeAnnot )
306
+ case _ => true
307
+ }
308
+ cpy.Block (shape0)(bindings ::: freshTypeBindings ::: otherStats, expr)
309
+ case _ =>
310
+ seq(freshTypeBindings, shape0)
311
+
306
312
val shape2 =
307
313
if (freshTypeBindings.isEmpty) shape1
308
314
else {
@@ -319,7 +325,7 @@ trait QuotesAndSplices {
319
325
new TreeTypeMap (typeMap = typeMap).transform(shape1)
320
326
}
321
327
322
- (typeBindings.toMap , shape2, patterns)
328
+ (typeBindings, shape2, patterns)
323
329
}
324
330
325
331
/** Type a quote pattern `case '{ <quoted> } =>` qiven the a current prototype. Typing the pattern
0 commit comments