Skip to content

Commit

Permalink
[NTI] Fix crash that comes up in mixin-style code.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145826102
  • Loading branch information
dimvar authored and blickly committed Jan 28, 2017
1 parent 9f94c3b commit 27852fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/com/google/javascript/jscomp/NewTypeInference.java
Expand Up @@ -624,7 +624,11 @@ private TypeEnv getTypeEnvFromDeclaredTypes() {
}
if (currentScope.isFunction()) {
Node fn = currentScope.getRoot();
if (!currentScope.hasThis() && NodeUtil.referencesSuper(fn)) {
if (!currentScope.hasThis()
// Can't use NodeUtil.referencesSuper here because that function is correct only
// on valid ASTs, but here we may have an invalid AST that contains super inside
// a function.
&& NodeUtil.containsType(fn.getLastChild(), Token.SUPER, NodeUtil.MATCH_NOT_FUNCTION)) {
// This function is a static method on some class. To do lookups of the
// class name, we add the root of the qualified name to the environment.
Node funNameNode = NodeUtil.getBestLValue(fn);
Expand Down
Expand Up @@ -336,4 +336,14 @@ public void testAbstractMethodCalls() {
" foo() { super.foo(); }",
"}"));
}

// super is handled natively in both type checkers, which results in ASTs that
// are temporarily invalid: a super call that is not in a class.
// Avoid crashing.
public void testDontCrashWithInvalidIntermediateASTwithSuper() {
typeCheck(LINE_JOINER.join(
"class Foo {}",
"function g(x) {}",
"g(function f(x) { return class extends Foo {} });"));
}
}

0 comments on commit 27852fc

Please sign in to comment.