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

Compiler crash using new.target with --language_out ECMASCRIPT_2019 #3607

Closed
AshleyScirra opened this issue May 27, 2020 · 1 comment
Closed
Assignees
Labels

Comments

@AshleyScirra
Copy link

Tested with Closure Compiler v20200517

Command: java -jar closure-compiler.jar --js in.js --js_output_file out.js --language_out ECMASCRIPT_2019

in.js:

window.Class = class {
	constructor()
	{
		let newTarget = new.target;
		return Object.create(newTarget.prototype);
	}
};

This crashes with IllegalStateException (full stack omitted for brevity):

java.lang.IllegalStateException: Unexpected expression node: NEW_TARGET 4 [length: 10] [source_file: in.js]
 parent:NAME newTarget 4 [length: 22] [source_file: in.js] [constant_var_flags: 2]
        at com.google.javascript.jscomp.NodeUtil.evaluatesToLocalValue(NodeUtil.java:4754)
        at com.google.javascript.jscomp.RemoveUnusedCode$NameDeclarationStatement.isAssignedValueLocal(RemoveUnusedCode.java:2384)
        at com.google.javascript.jscomp.RemoveUnusedCode$VarInfo.addRemovable(RemoveUnusedCode.java:2670)
        at com.google.javascript.jscomp.RemoveUnusedCode.traverseDeclarationStatement(RemoveUnusedCode.java:1038)

Another seemingly related case is the following:

window.Class = class {
	constructor()
	{
		return new.target;
	}
};

This crashes too but only in ADVANCED compilation mode. Full command line:
java -jar closure-compiler.jar --js in.js --js_output_file out.js --language_out ECMASCRIPT_2019 --compilation_level ADVANCED

This crashes with INTERNAL COMPILER ERROR (full stack omitted for brevity):

in.js:4: WARNING - [JSC_TYPE_MISMATCH] inconsistent return type
found   : Function
required: window.Class
                return new.target;
                       ^^^^^^^^^^

0 error(s), 1 warning(s), 100.0% typed
java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.

Unexpected expression node: NEW_TARGET 4 [length: 10] [source_file: in.js] : Function
 parent:RETURN 4 [length: 18] [source_file: in.js]
  Node(RETURN): in.js:4:2
                return new.target;
  Parent(BLOCK): in.js:3:1
        {

        at com.google.javascript.jscomp.NodeUtil.evaluatesToLocalValue(NodeUtil.java:4754)
        at com.google.javascript.jscomp.PureFunctionIdentifier$FunctionBodyAnalyzer.updateSideEffectsForNode(PureFunctionIdentifier.java:829)
        at com.google.javascript.jscomp.PureFunctionIdentifier$FunctionBodyAnalyzer.visit(PureFunctionIdentifier.java:709)
        at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:909)
@brad4d brad4d self-assigned this May 27, 2020
@brad4d brad4d added the P2 label May 27, 2020
@concavelenz
Copy link
Contributor

The fix for this should be trivial, I put together a change

@concavelenz concavelenz assigned concavelenz and unassigned brad4d Jun 22, 2020
patrick-sko added a commit to patrick-sko/closure-compiler that referenced this issue Jun 23, 2020
Remove unused CompilerOption aggressiveFusion

This option was originally added in case we wanted to favor fusing statements via commas rather than semicolons. However, since the option is still unused and non-public after about seven years, I don't see any reason to keep it around.

PiperOrigin-RevId: 316715205

captureTimestamp defined as https://w3c.github.io/webrtc-extensions/#dom-rtcrtpcontributingsource-capturetimestamp

PiperOrigin-RevId: 316729289

Fixing BigInt.matchesNumberContext() to return false
While BigInt acts like a number, it cannot be converted to the JS type, number. So, we need to make sure there is no confusion about this within the compiler.

PiperOrigin-RevId: 316734057

Allow JSRefaster to use "typeof xxx" in template matches

PiperOrigin-RevId: 316753547

Adding master utility function for BigIntType

PiperOrigin-RevId: 316788565

Fix RhinoNodeTokenShortcut build warning

PiperOrigin-RevId: 316788950

Remove declaredGlobalExternsOnWindow CompilerOption since it's always true

The only place setting it to false is in unit tests, and all relevant unit tests pass without this option.

PiperOrigin-RevId: 316796485

Add type inference and typechecking of unary plus on a BigInt

PiperOrigin-RevId: 316801858

Type inferencing for unary minus on BigInt

PiperOrigin-RevId: 316802254

Remove warning for missing a translation for @alternateMessageId.

PiperOrigin-RevId: 316929911

Upgrade the open source GWTed JSCompiler dependencies to GWT 2.9.0, elemental2-core 1.0.0 and jsinterop-annotations 2.0.0

PiperOrigin-RevId: 316943720

Creating native type BIGINT_NUMBER

PiperOrigin-RevId: 316960600

Type inferencing for logical NOT on BigInt

PiperOrigin-RevId: 316967762

Avoid trying to remove code twice to avoid a crash.

Fixes google#3612

PiperOrigin-RevId: 316992435

Allow class members named "static"

Fixes google#3614

PiperOrigin-RevId: 316998116

Replacing with BIGINT_NUMBER native type where necessary, clarifying test name

PiperOrigin-RevId: 317013897

Adding TypeInference tests for `typeof` operation on BigInt

PiperOrigin-RevId: 317015720

Adding TypeInference tests for `delete` operation on BigInt

PiperOrigin-RevId: 317015993

Adding TypeInference tests for `void` operation on BigInt

PiperOrigin-RevId: 317016205

Moving BigIntPresence to TypeInference

PiperOrigin-RevId: 317121298

Add bug link for a test case that currently generates bad fixes

PiperOrigin-RevId: 317129859

Cleaning up utility functions in TypeInference and TypeCheck

PiperOrigin-RevId: 317187656

Replace the use of 'blacklist' where it is trivial to do so.

PiperOrigin-RevId: 317191902

Create an flag alias for warnings_whitelist_file: warnings_allowlist_file

PiperOrigin-RevId: 317192497

Type checking for logical NOT on BigInt

PiperOrigin-RevId: 317194139

Type inferencing for bitwise NOT on BigInt

PiperOrigin-RevId: 317194899

AstValidator: optional chains cannot start with `super`

Actually AstValidator was already reporting an error as it should,
thus there are no test changes here.

However, it was reporting the error as part of validating the SUPER node,
while simultaneously incorrectly validating the OPTCHAIN_GETPROP or
OPTCHAIN_GETELEM that had SUPER as it's first child.

This little fix is really just to avoid a potential future bug when
someone refactors the code in a way that stops hiding the fact that
the validation for GETPROP and GETELEM were wrong.

PiperOrigin-RevId: 317210405

Replace 'whitelist' where it is trivial to do so.

PiperOrigin-RevId: 317216394

Extract out createModule* methods from CompilerTestCase

This unblocks using these methods from an upcoming .integration package

PiperOrigin-RevId: 317345333

Allow code printer to print nonJSDoc source comments in output

Adds a compiler option to print nonJSDoc source comments in output JS. Handles trailing, non-trailing, inline and regular comments.

PiperOrigin-RevId: 317362606

Deprecate event.cancelBubble

PiperOrigin-RevId: 317363515

AstChainOptionalizer: utility to aid addition of optional chain support

Add a temporary utility to CompilerTestCase allowing one to make an existing
test class run all of its test cases in a way that checks equivalent cases
using optional chaining.

1. Wherever it is valid to do so, change all CALL, GETPROP, and GETELEM nodes
   in the input JS code to the OPTCHAIN_* version of that node.
2. Process the code.
3. Change all of the OPTCHAIN_* nodes in the result back to their non-OPTCHAIN_
   versions.

The idea is to use this utility in a working directory to identify problem
spots, fix them, and add a few targeted test cases for optional chains.

No test classes should be commited to the repository with this feature enabled.
It should be removed entirely once support for optional chaining is complete.

PiperOrigin-RevId: 317381855

added support for deprecated flags in public method

Fix some build failures

Added enum to gwt java filer

Fixed gwt build error

Undid test checK

Addressed pr comments and fixed some style issues

Fixed build issue relating to gwt

Fixed unit test failure

Adding expectBigIntOrNumber() to TypeValidator

PiperOrigin-RevId: 317409827

NodeUtil.isGet() -> NodeUtil.isNormalGet()

* NodeUtil.isGet() is renamed to isNormalGet()
* Added NodeUtil.isNormalOrOptChainGet() which is true for both normal and optional
  chain gets.
* Most callers of isGet() were changed to use isNormalGet().
* A few places that called both isGet() and isOptChainGet() were changed to call
  isNormalOrOptChainGet().
* It is likely that other callers of isNormalGet() will also be changed to
  use isNormalOrOptChainGet() as we add support for optional chains.

PiperOrigin-RevId: 317666732

Fixes google#3607

PiperOrigin-RevId: 317693198

Remove 'ShadowVariables' functionality due to build performance issues.

PiperOrigin-RevId: 317734020

Add template parameters for async generator return value and next(value)

The template parameters are not yet used to affect the prototype methods.
That requires more extensive changes and probably fixes to client code.

However, this change is sufficient to avoid complaining when client code
uses 3 template parameters, as happens when the async generator d.ts definitions
are used with tsickle to generate closure JS from TS.

PiperOrigin-RevId: 317743376

Minor style change

Addressed remainder of PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants