diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-28 11:29:28 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 14:08:57 +0100 |
commit | 51b16e421ddd4e6c7e90ba945addf39ffcb4fa41 (patch) | |
tree | d002d3dccfe613f830862a259957154523a21488 /src/compiler | |
parent | edadc01df2cbac2c8a00c2e0cc520713690418b9 (diff) | |
download | scala-51b16e421ddd4e6c7e90ba945addf39ffcb4fa41.tar.gz scala-51b16e421ddd4e6c7e90ba945addf39ffcb4fa41.tar.bz2 scala-51b16e421ddd4e6c7e90ba945addf39ffcb4fa41.zip |
SI-8192 adds ClassSymbol.isPrimaryConstructor
Exposes a popular code pattern in macros as a dedicated reflection API.
This simple commit, however, ended up being not so simple, as it often
happens with our compiler.
When writing a test for the new API, I realized that our (pre-existing)
MethodSymbol.isPrimaryConstructor API returns nonsensical results for
implementation artifacts (trait mixin ctors, module class ctors).
What’s even more funny is that according to our reflection internals,
even Java classes have primary constructors. Well, that’s not surprising,
because `primaryConstructor` is just `decl(ctorName).alternatives.head`.
Good thing that package classes don’t have constructors or that would
elevate the situation to three fries short of a happy meal.
At the moment, I’m too scared to fiddle with internal#Symbol.primaryConstructor,
because that could easily break someone right before RC1, so I simply
documented the findings in SI-8193 and postponed the actual work, except
for one thing - isJavaDefined symbols no longer have primary constructors.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 60c1553ef3..eba2e1399d 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -597,7 +597,7 @@ abstract class Erasure extends AddInterfaces if (tree.symbol == NoSymbol) { tree } else if (name == nme.CONSTRUCTOR) { - if (tree.symbol.owner == AnyValClass) tree.symbol = ObjectClass.primaryConstructor + if (tree.symbol.owner == AnyValClass) tree.symbol = ObjectClass.info.decl(nme.CONSTRUCTOR) tree } else if (tree.symbol == Any_asInstanceOf) adaptMember(atPos(tree.pos)(Select(qual, Object_asInstanceOf))) @@ -737,7 +737,7 @@ abstract class Erasure extends AddInterfaces /** TODO - adapt SymbolPairs so it can be used here. */ private def checkNoDeclaredDoubleDefs(base: Symbol) { val decls = base.info.decls - + // SI-8010 force infos, otherwise makeNotPrivate in ExplicitOuter info transformer can trigger // a scope rehash while were iterating and we can see the same entry twice! // Inspection of SymbolPairs (the basis of OverridingPairs), suggests that it is immune @@ -748,13 +748,13 @@ abstract class Erasure extends AddInterfaces // we do these checks, so that we're comparing same-named methods based on the expanded names that actually // end up in the bytecode. exitingPostErasure(decls.foreach(_.info)) - + var e = decls.elems while (e ne null) { if (e.sym.isTerm) { var e1 = decls lookupNextEntry e while (e1 ne null) { - assert(e.sym ne e1.sym, s"Internal error: encountered ${e.sym.debugLocationString} twice during scope traversal. This might be related to SI-8010.") + assert(e.sym ne e1.sym, s"Internal error: encountered ${e.sym.debugLocationString} twice during scope traversal. This might be related to SI-8010.") if (sameTypeAfterErasure(e.sym, e1.sym)) doubleDefError(new SymbolPair(base, e.sym, e1.sym)) |