@@ -3018,7 +3018,33 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
3018
3018
def memberTypes : List [Symbol ] =
3019
3019
self.typeRef.decls.filter(_.isType)
3020
3020
def typeMembers : List [Symbol ] =
3021
- lookupPrefix.typeMembers.map(_.symbol).toList
3021
+ // lookupPrefix.typeMembers currently returns a Set wrapped into a unsorted Seq,
3022
+ // so we try to sort that here (see discussion: https://github.com/scala/scala3/issues/22472),
3023
+ // without adding too much of a performance hit.
3024
+ // It first sorts by parents, then for type params by their positioning, then for members
3025
+ // derived from declarations it sorts them by their name lexicographically
3026
+ val parentsMap = lookupPrefix.sortedParents.map(_.typeSymbol).zipWithIndex.toList.toMap
3027
+ val unsortedTypeMembers = lookupPrefix.typeMembers.map(_.symbol).filter(_.exists).toList
3028
+ unsortedTypeMembers.sortWith {
3029
+ case (typeA, typeB) =>
3030
+ val msg = " Unknown type member found. Please consider reporting the issue to the compiler. "
3031
+ assert(parentsMap.contains(typeA.owner), msg)
3032
+ assert(parentsMap.contains(typeB.owner), msg)
3033
+ val parentPlacementA = parentsMap(typeA.owner)
3034
+ val parentPlacementB = parentsMap(typeB.owner)
3035
+ if (parentPlacementA == parentPlacementB) then
3036
+ if typeA.isTypeParam && typeB.isTypeParam then
3037
+ // put type params at the beginning (and sort them by declaration order)
3038
+ val pl = typeA.owner
3039
+ val typeParamPositionMap = pl.typeParams.map(_.asInstanceOf [Symbol ]).zipWithIndex.toMap
3040
+ typeParamPositionMap(typeA) < typeParamPositionMap(typeB)
3041
+ else if typeA.isTypeParam then true
3042
+ else if typeB.isTypeParam then false
3043
+ else
3044
+ // sort by name lexicographically
3045
+ typeA.name.toString().compareTo(typeB.name.toString()) < 0
3046
+ else parentPlacementA < parentPlacementB
3047
+ }.map(_.asInstanceOf [Symbol ])
3022
3048
3023
3049
def declarations : List [Symbol ] =
3024
3050
self.typeRef.info.decls.toList
0 commit comments