-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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)
b026c5d
to
cc86be4
Compare
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.
cc86be4
to
e9b62b7
Compare
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.
e9b62b7
to
c94c58e
Compare
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
No description provided.