Skip to content

Fix #3638: Fix protected setter generation #3715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 4, 2018

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 31, 2017

No description provided.

@odersky odersky changed the title Fix protected setter generation Fix #3638: Fix protected setter generation Dec 31, 2017
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Fix #3638" should appear somewhere in the commit message.

@@ -0,0 +1,12 @@
package p {
package a {
class JavaInteraction(arr: Array[Char])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this test was minimized from https://github.com/scala/scala/blob/2.13.x/test/files/jvm/protectedacc.scala, it might be worthwhile to port over the whole test (I think it's a run test but it's in /jvm and not /run so it might need to be run in a special way?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can't run on JS because it uses Java classes, that's why it's in jvm. I added the full test to run.

As @smarter has noticed, the original i3638 seems to be a distillation of this larger test.
@odersky
Copy link
Contributor Author

odersky commented Jan 2, 2018

@nicolasstucki The FromTasty test fails on protectedacc.scala. Can you take a look to find out what's wrong?

@nicolasstucki
Copy link
Contributor

I will have a look

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jan 2, 2018

I minimized that issue to

package a {
  class PolyA {
    protected def m(): Unit = ()
  }
}

class X extends a.PolyA {
  trait Inner {
    m()
  }
}

which can be reproduced with

dotc -d out <sourceAbove>
dotc -from-tasty -Ycheck:elimJavaPackages,refchecks,splitter,arrayConstructors,erasure,capturedVars,getClass,elimStaticThis,labelDef -classpath out X a.PolyA 

and fails with

checking out2/a/PolyA.class after phase MegaPhase{checkStatic, elimRepeated, normalizeFlags, extmethods, expandSAMs, tailrec, byNameClosures, liftTry, hoistSuperArgs, classOf, refchecks}
Exception in thread "main" java.lang.AssertionError: assertion failed: method super$m is both Deferred and Private
	at scala.Predef$.assert(Predef.scala:219)
	at dotty.tools.dotc.transform.TreeChecker.transformSym(TreeChecker.scala:95)
	at dotty.tools.dotc.core.DenotTransformers$SymTransformer.transform(DenotTransformers.scala:68)
	at dotty.tools.dotc.core.DenotTransformers$SymTransformer.transform$(DenotTransformers.scala:67)
	at dotty.tools.dotc.transform.TreeChecker.transform(TreeChecker.scala:48)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:872)
	at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:432)
	at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:427)
	at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:421)
	at dotty.tools.dotc.core.Symbols$.toDenot(Symbols.scala:684)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.$anonfun$paramAccessors$1(SymDenotations.scala:1765)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.$anonfun$paramAccessors$1$adapted(SymDenotations.scala:1765)
	at dotty.tools.dotc.core.Scopes$Scope.filter(Scopes.scala:104)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.paramAccessors(SymDenotations.scala:1765)
	at dotty.tools.dotc.core.Contexts$Context.superCallContext(Contexts.scala:328)
...

@nicolasstucki
Copy link
Contributor

The failure is after refchecks

@nicolasstucki
Copy link
Contributor

The bug in tests/run/protectedacc.scala when tested from TASTY in unrelated to this fix. I filed an issue and added it to the backlist of the FromTastyTests. This PR should be mergeable if the tests pass.

The previous logic made a super accessor private if it is put in a class (on behalf
of a nested trait). This caused compilation from Tasty to fail, since at the point
of Tasty generation the RHS of the accessor has not yet been generated (it will be
generated later in resolveSuper), and therefore Unpickler concluded that the method
is private and deferred, which is illegal.

Making it private is anyway pointless, since the super accessor is referred to from
an inner trait (that's why it was generated in the first place!) and therefore will
be made non-private later on.
@@ -80,10 +80,10 @@ class SuperAccessors(thisPhase: DenotTransformer) {
val superAcc = clazz.info.decl(superName)
.suchThat(_.signature == superInfo.signature).symbol
.orElse {
ctx.debuglog(s"add super acc ${sym.showLocated} to $clazz")
val deferredOrPrivate = if (clazz is Trait) Deferred else Private
ctx.debugLog(s"add super acc ${sym.showLocated} to $clazz")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.debugLog -> ctx.debuglog

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit should also Fix #3738

@nicolasstucki
Copy link
Contributor

Otherwise LGTM

@odersky odersky merged commit 738cefb into scala:master Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants