Skip to content

Simplify super call handling: remove inConstrCall, remove InSuperCall #8591

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 3 commits into from
Mar 22, 2020

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 22, 2020

No description provided.

The `inConstrCall` parameter passed to `tpd.Super` and `assignType`
should be true for super-calls to parent class constructors and false
otherwise, this is used to correctly type the Super node:

    else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent.typeConstructor

But calls to super-constructor are only generated by Mixin which runs
after Erasure, so we can don't `inConstrCall` to take the correct branch.

There were two places before erasure where we didn't just pass
`inConstrCall = false` and they were both wrong:
- In Typer, we had:
      case pt: SelectionProto if pt.name == nme.CONSTRUCTOR => true
  But Typer never generates super-calls to constructors (such calls are
  just regular constructor calls in the extends clause until Mixin)
- In TreeUnpickler, we had:
      ctx.mode.is(Mode.InSuperCall)
  Which doesn't really make sense (it checks whether the super-call is
  happening inside the extends clause or a secondary constructor)
@smarter smarter force-pushed the try/super-constr-call branch from b026c5d to cc86be4 Compare March 22, 2020 17:33
After the previous commit, there was one usage of InSuperCall left in
typedIdent to provide a better error message, but that usage can be
replaced by a check to make sure we're in a secondary constructor
instead, which means we can get rid of this mode avoid having to set and
unset it in a bunch of places.
@smarter smarter force-pushed the try/super-constr-call branch from cc86be4 to e9b62b7 Compare March 22, 2020 18:09
We could use a context function but for now let's avoid using Scala 3
features in the tasty code to make it easier to port to Scala 2.
@smarter smarter force-pushed the try/super-constr-call branch from e9b62b7 to c94c58e Compare March 22, 2020 18:10
@smarter smarter requested a review from odersky March 22, 2020 18:11
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

That's a nice simplification!

@@ -670,7 +670,7 @@ class TreeUnpickler(reader: TastyReader,
readByte()
val end = readEnd()
val tp = readType()
val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx))
val lazyAnnotTree = readLaterWithOwner(end, rdr => implicit ctx => rdr.readTerm())
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose we go to the new syntax (using ctx) => rdr.readTerm().

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't work because the expected type is not a context function type but a regular function type, and I was hesitant to change this since it'll make it harder to port code between the Scala 2 and 3 readers.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@@ -780,7 +780,7 @@ class TreeUnpickler(reader: TastyReader,
def complete(implicit ctx: Context) = typer.Inliner.bodyToInline(sym)
}
else
readLater(end, rdr => ctx => rdr.readTerm()(ctx))
readLater(end, rdr => implicit ctx => rdr.readTerm())
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@smarter smarter merged commit 42932dc into scala:master Mar 22, 2020
@smarter smarter deleted the try/super-constr-call branch March 22, 2020 21:02
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.

2 participants