Skip to content

Commit

Permalink
Fix NPE for creating error messages around unknown interface ancestors
Browse files Browse the repository at this point in the history
This fixes a recent unreleased regression.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=246043186
  • Loading branch information
gkdn authored and brad4d committed May 1, 2019
1 parent 60f9835 commit 8d7f876
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/com/google/javascript/rhino/jstype/ObjectType.java
Expand Up @@ -311,7 +311,9 @@ public final ObjectType getTopDefiningInterface(String propertyName) {
}
}

if (hasOwnProperty(propertyName) || getImplicitPrototype().hasOwnProperty(propertyName)) {
ObjectType implicitPrototype = getImplicitPrototype();
if (hasOwnProperty(propertyName)
|| (implicitPrototype != null && implicitPrototype.hasOwnProperty(propertyName))) {
return this;
}

Expand Down
19 changes: 19 additions & 0 deletions test/com/google/javascript/jscomp/TypeCheckTest.java
Expand Up @@ -8380,6 +8380,25 @@ public void testOverriddenPropertyWithUnknown() {
"property bar already defined on superclass Foo; use @override to override it");
}

@Test
public void testOverriddenPropertyWithUnknownInterfaceAncestor() {
testTypes(
lines(
"/** @interface @extends {Unknown} */ function Foo() {}",
"/** @type {string} */ Foo.prototype.data;",
"/** @constructor @implements {Foo} */ function SubFoo() {}",
"/** @type {string|Object} */ ",
"SubFoo.prototype.data = null;"),
new String[] {
"Bad type annotation. Unknown type Unknown",
lines(
"mismatch of the data property on type SubFoo and the type "
+ "of the property it overrides from interface Foo",
"original: string",
"override: (Object|string)")
});
}

@Test
public void testThis2() {
testTypes("var goog = {};" +
Expand Down

0 comments on commit 8d7f876

Please sign in to comment.