summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-01-30 16:25:53 -0800
committerPaul Phillips <paulp@improving.org>2013-01-30 16:25:53 -0800
commitd24f341f081aef296d174ea54d0579976eeaae98 (patch)
treec708611aeb7bed6d2b7e05ee408a028a88b50150 /src/reflect
parent7d80e0846964053b81b4e4b5db7b9356e3bcc601 (diff)
parent9afae59f0e46bed0acf40d043d3ee2a0e0ef432f (diff)
downloadscala-d24f341f081aef296d174ea54d0579976eeaae98.tar.gz
scala-d24f341f081aef296d174ea54d0579976eeaae98.tar.bz2
scala-d24f341f081aef296d174ea54d0579976eeaae98.zip
Merge pull request #1997 from retronym/ticket/7035
SI-7035 Centralize case field accessor sorting.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index c274a9e3af..c1b868f3cb 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -1730,8 +1730,27 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** For a case class, the symbols of the accessor methods, one for each
* argument in the first parameter list of the primary constructor.
* The empty list for all other classes.
- */
- final def caseFieldAccessors: List[Symbol] =
+ *
+ * This list will be sorted to correspond to the declaration order
+ * in the constructor parameter
+ */
+ final def caseFieldAccessors: List[Symbol] = {
+ // We can't rely on the ordering of the case field accessors within decls --
+ // handling of non-public parameters seems to change the order (see SI-7035.)
+ //
+ // Luckily, the constrParamAccessors are still sorted properly, so sort the field-accessors using them
+ // (need to undo name-mangling, including the sneaky trailing whitespace)
+ //
+ // The slightly more principled approach of using the paramss of the
+ // primary constructor leads to cycles in, for example, pos/t5084.scala.
+ val primaryNames = constrParamAccessors.map(acc => nme.dropLocalSuffix(acc.name))
+ caseFieldAccessorsUnsorted.sortBy { acc =>
+ primaryNames indexWhere { orig =>
+ (acc.name == orig) || (acc.name startsWith (orig append "$"))
+ }
+ }
+ }
+ private final def caseFieldAccessorsUnsorted: List[Symbol] =
(info.decls filter (_.isCaseAccessorMethod)).toList
final def constrParamAccessors: List[Symbol] =