Skip to content

Commit

Permalink
[NTI] Clean up some cases of method overrides involving @export and u…
Browse files Browse the repository at this point in the history
…nions of functions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148695430
  • Loading branch information
dimvar authored and brad4d committed Feb 28, 2017
1 parent 6b81fd0 commit 67ee12a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/com/google/javascript/jscomp/GlobalTypeInfo.java
Expand Up @@ -757,8 +757,8 @@ private void checkSuperProperty(
} }


private boolean isValidOverride(JSType localPropType, JSType inheritedPropType) { private boolean isValidOverride(JSType localPropType, JSType inheritedPropType) {
FunctionType localFunType = localPropType.getFunTypeIfSingletonObj(); FunctionType localFunType = localPropType.getFunType();
FunctionType inheritedFunType = inheritedPropType.getFunTypeIfSingletonObj(); FunctionType inheritedFunType = inheritedPropType.getFunType();
if (localFunType == null) { if (localFunType == null) {
return localPropType.isSubtypeOf(inheritedPropType); return localPropType.isSubtypeOf(inheritedPropType);
} else if (inheritedFunType == null) { } else if (inheritedFunType == null) {
Expand All @@ -773,7 +773,10 @@ private static boolean getsTypeInfoFromParentMethod(PropertyDef pd) {
return false; return false;
} }
JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(pd.defSite); JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(pd.defSite);
return jsdoc == null || (jsdoc.isOverride() && !jsdoc.containsFunctionDeclaration()); if (jsdoc == null) {
return true;
}
return (jsdoc.isOverride() || jsdoc.isExport()) && !jsdoc.containsFunctionDeclaration();
} }


/** /**
Expand Down
42 changes: 41 additions & 1 deletion test/com/google/javascript/jscomp/NewTypeInferenceTest.java
Expand Up @@ -4222,7 +4222,7 @@ public void testWarnAboutOverridesNotVisibleDuringGlobalTypeInfo() {
GlobalTypeInfo.INVALID_PROP_OVERRIDE); GlobalTypeInfo.INVALID_PROP_OVERRIDE);
} }


public void testInvalidMethodPropertyOverride() { public void testMethodPropertyOverride() {
typeCheck(LINE_JOINER.join( typeCheck(LINE_JOINER.join(
"/** @interface */ function Parent() {}", "/** @interface */ function Parent() {}",
"/** @type {number} */ Parent.prototype.y;", "/** @type {number} */ Parent.prototype.y;",
Expand Down Expand Up @@ -4259,6 +4259,46 @@ public void testInvalidMethodPropertyOverride() {
"function Bar() {}", "function Bar() {}",
"/** @override */", "/** @override */",
"Bar.prototype.f = function(x) {};")); "Bar.prototype.f = function(x) {};"));

typeCheck(LINE_JOINER.join(
"/** @constructor */",
"function Foo() {}",
"/** @type {function()|undefined} */",
"Foo.prototype.method;",
"/**",
" * @constructor",
" * @extends {Foo}",
" */",
"function Baz() {}",
"/** @export */",
"Baz.prototype.method = function() {};"));

typeCheck(LINE_JOINER.join(
"/** @constructor */",
"function Foo() {}",
"/** @type {function(number=)} */",
"Foo.prototype.method;",
"/**",
" * @constructor",
" * @extends {Foo}",
" */",
"function Baz() {}",
"/** @export */",
"Baz.prototype.method = function(x) {};",
"(new Baz).method();"));

typeCheck(LINE_JOINER.join(
"/** @constructor */",
"function Foo() {}",
"/** @type {function(number)|undefined} */",
"Foo.prototype.method;",
"/**",
" * @constructor",
" * @extends {Foo}",
" */",
"function Baz() {}",
"/** @param {number} x */",
"Baz.prototype.method = function(x) {};"));
} }


public void testMultipleObjects() { public void testMultipleObjects() {
Expand Down

0 comments on commit 67ee12a

Please sign in to comment.