Skip to content
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

Prevent calls to super outside of a constructor #2452

Conversation

ChadKillingsworth
Copy link
Collaborator

Prerequisite for #2418

Emit errors for calls to super outside of a constructor.

Copy link
Contributor

@brad4d brad4d left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on.
Just one small requested change.

@@ -58,6 +58,10 @@
"JSC_CANNOT_CONVERT_YET",
"ES6 transpilation of ''{0}'' is not yet implemented.");

static final DiagnosticType INVALID_SUPER =
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you rename this to INVALID_SUPER_CALL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@brad4d Fixed

@brad4d brad4d self-assigned this May 1, 2017
@ChadKillingsworth ChadKillingsworth force-pushed the super-calls-online-in-constructor branch from cc8e8c3 to 077ab55 Compare May 2, 2017 00:55
@brad4d
Copy link
Contributor

brad4d commented May 3, 2017

@ChadKillingsworth sorry, but @MatrixFrog refactored class transpilation out of Es6ToEs3Converter.java and into its own file. Could you resolve?

@MatrixFrog
Copy link
Contributor

MatrixFrog commented May 3, 2017 via email

@ChadKillingsworth ChadKillingsworth force-pushed the super-calls-online-in-constructor branch from 077ab55 to 960f150 Compare May 3, 2017 02:02
@ChadKillingsworth
Copy link
Collaborator Author

All fixed - it barely conflicted

@ChadKillingsworth ChadKillingsworth force-pushed the super-calls-online-in-constructor branch from 960f150 to c3eed57 Compare May 3, 2017 02:05
@brad4d
Copy link
Contributor

brad4d commented May 3, 2017

Sent for internal testing and review.


if (exprRoot.getParent().isNew()) {
compiler.report(JSError.make(node, INVALID_SUPER_CALL));
} else if (NodeUtil.isCallOrNewTarget(exprRoot)
Copy link
Contributor

Choose a reason for hiding this comment

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

why isCallOrNewTarget() here?
It's redundant with the previous if.

potentialCallee = parent;
Node exprRoot = node;

if (exprRoot.getParent().isGetElem() || exprRoot.getParent().isGetProp()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

An internal test system found that changing this to be if (true) { didn't cause any test failures.
This implies a missing test and made me realize it's not as clear as it should be what's happening here.

Could this logic be clarified to something like this?

private void visitSuper(Node superNode, Node parent) {
  checkState(superNode.isSuper());
  if (parent.isCall()) {
    // super(...)
    visitBareSuperCall(superNode, parent);
  } else if (parent.isGetProp()) {
    checkState(parent.getFirstChild() == superNode);
    // super.something
    if (parent.getParent().isCall()) {
      // super.something(...)
      visitSuperDotSomethingCall(superNode, parent);
    } else {
      // super.something used in some other way
      // report not supported yet error
    }
  } else if (parent.isGetElem()) {
    checkState(superNode == parent.getFirstChild());
    // super[...]
    // report not supported yet error
  } else if (parent.isNew()) {
    // new super(...)
    // invalid use of super
  } else {
    // some other use of super we don't support yet
  }
}

@brad4d
Copy link
Contributor

brad4d commented May 16, 2017

ping @ChadKillingsworth
FYI, I'm waiting for your response / changes before proceeding with this.

@ChadKillingsworth
Copy link
Collaborator Author

@brad4d I've been slammed - I hope to get back to this soon.

@brad4d
Copy link
Contributor

brad4d commented May 18, 2017

@ChadKillingsworth
np
I just wanted to make sure we weren't both waiting on each other.

@ChadKillingsworth
Copy link
Collaborator Author

@brad4d Changes made.

@brad4d
Copy link
Contributor

brad4d commented May 25, 2017

@ChadKillingsworth
imported and running through tests
thanks

@brad4d
Copy link
Contributor

brad4d commented May 26, 2017

test results look good
sent to @MatrixFrog for internal review

@blickly blickly closed this in fdf120f May 26, 2017
@ChadKillingsworth ChadKillingsworth deleted the super-calls-online-in-constructor branch June 13, 2017 11:14
Yannic pushed a commit to Yannic/com_google_closure_compiler that referenced this pull request Jul 6, 2017
Closes google#2452

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157253710
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants