Skip to content

Commit

Permalink
Automated g4 rollback of changelist 184019882.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Creates a release blocker that needs fixing before rolling forward.

*** Original change description ***

Fix bug in the old type checker where a stub method definition causes loss of type checking.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184218181
  • Loading branch information
blickly authored and lauraharker committed Feb 2, 2018
1 parent 7adf579 commit 8b29a25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 62 deletions.
24 changes: 3 additions & 21 deletions src/com/google/javascript/jscomp/TypedScopeCreator.java
Expand Up @@ -1806,22 +1806,6 @@ private ObjectType getObjectSlot(String slotName) {
return null;
}

/**
* When a class has a stub for a property, and the property exists on a super interface,
* use that type.
*/
private JSType getInheritedInterfacePropertyType(ObjectType obj, String propName) {
if (obj != null && obj.isPrototypeObject()) {
FunctionType f = obj.getOwnerFunction();
for (ObjectType i : f.getImplementedInterfaces()) {
if (i.hasProperty(propName)) {
return i.getPropertyType(propName);
}
}
}
return null;
}

/**
* Resolve any stub declarations to unknown types if we could not
* find types for them during traversal.
Expand All @@ -1842,19 +1826,17 @@ void resolveStubDeclarations() {
// If we see a stub property, make sure to register this property
// in the type registry.
ObjectType ownerType = getObjectSlot(ownerName);
JSType inheritedType = getInheritedInterfacePropertyType(ownerType, propName);
JSType stubType = inheritedType == null ? unknownType : inheritedType;
defineSlot(n, parent, stubType, true);
defineSlot(n, parent, unknownType, true);

if (ownerType != null &&
(isExtern || ownerType.isFunctionPrototypeType())) {
// If this is a stub for a prototype, just declare it
// as an unknown type. These are seen often in externs.
ownerType.defineInferredProperty(
propName, stubType, n);
propName, unknownType, n);
} else {
typeRegistry.registerPropertyOnType(
propName, ownerType == null ? stubType : ownerType);
propName, ownerType == null ? unknownType : ownerType);
}
}
}
Expand Down
41 changes: 0 additions & 41 deletions test/com/google/javascript/jscomp/TypeCheckTest.java
Expand Up @@ -2951,47 +2951,6 @@ public void testStubFunctionDeclaration10() {
"function(number): number");
}


public void testStubMethodDeclarationDoesntBlockTypechecking_1() {
testTypes(
lines(
"/** @interface */",
"function Foo() {}",
"/** @return {number} */",
"Foo.prototype.method = function() {};",
"/**",
" * @constructor",
" * @implements {Foo}",
" */",
"function Bar() {}",
"Bar.prototype.method;",
"var /** null */ n = (new Bar).method();"),
lines(
"initializing variable",
"found : number",
"required: null"));
}

public void testStubMethodDeclarationDoesntBlockTypechecking_2() {
testTypes(
lines(
"/** @constructor */",
"function Foo() {}",
"/** @return {number} */",
"Foo.prototype.method = function() {};",
"/**",
" * @constructor",
" * @extends {Foo}",
" */",
"function Bar() {}",
"Bar.prototype.method;",
"var /** null */ n = (new Bar).method();"),
lines(
"initializing variable",
"found : number",
"required: null"));
}

public void testNestedFunctionInference1() {
String nestedAssignOfFooAndBar =
"/** @constructor */ function f() {};" +
Expand Down

0 comments on commit 8b29a25

Please sign in to comment.