diff options
-rw-r--r-- | src/reflect/scala/reflect/internal/Symbols.scala | 17 | ||||
-rw-r--r-- | test/files/run/t8087.scala | 12 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 44fce2c9ab..b0c23ef45d 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2023,12 +2023,19 @@ trait Symbols extends api.Symbols { self: SymbolTable => info.decls.filter(sym => !sym.isMethod && sym.isParamAccessor).toList /** The symbol accessed by this accessor (getter or setter) function. */ - final def accessed: Symbol = accessed(owner.info) - - /** The symbol accessed by this accessor function, but with given owner type. */ - final def accessed(ownerTp: Type): Symbol = { + final def accessed: Symbol = { assert(hasAccessorFlag, this) - ownerTp decl localName + val localField = owner.info decl localName + + if (localField == NoSymbol && this.hasFlag(MIXEDIN)) { + // SI-8087: private[this] fields don't have a `localName`. When searching the accessed field + // for a mixin accessor of such a field, we need to look for `name` instead. + // The phase travel ensures that the field is found (`owner` is the trait class symbol, the + // field gets removed from there in later phases). + enteringPhase(picklerPhase)(owner.info).decl(name).suchThat(!_.isAccessor) + } else { + localField + } } /** The module corresponding to this module class (note that this diff --git a/test/files/run/t8087.scala b/test/files/run/t8087.scala new file mode 100644 index 0000000000..6047211756 --- /dev/null +++ b/test/files/run/t8087.scala @@ -0,0 +1,12 @@ +trait Foo { + @volatile private[this] var x: String = "" + @volatile private var y: String = "" +} + +class Bar extends Foo + +object Test extends App { + classOf[Bar].getDeclaredFields.foreach(f => { + assert(java.lang.reflect.Modifier.isVolatile(f.getModifiers), f.getName) + }) +} |