Skip to content

Commit

Permalink
Rollback of "Fix bug in DisambiguateProperties involving generic inte…
Browse files Browse the repository at this point in the history
…rfac..."

There are some remaining issues that need to be fixed before this
can be rolled forward.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128065971
  • Loading branch information
dimvar authored and blickly committed Jul 21, 2016
1 parent 2e8835f commit 8759434
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 92 deletions.
23 changes: 4 additions & 19 deletions src/com/google/javascript/rhino/jstype/PropertyMap.java
Expand Up @@ -44,11 +44,9 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -165,29 +163,16 @@ Set<String> getOwnPropertyNames() {
}

void collectPropertyNames(Set<String> props) {
Set<PropertyMap> identitySet = Sets.newIdentityHashSet();
collectPropertyNamesHelper(props, identitySet);
}

// The interface inheritance chain can have cycles.
// Use cache to avoid stack overflow.
private void collectPropertyNamesHelper(
Set<String> props, Set<PropertyMap> cache) {
if (cache.contains(this)) {
return;
}
cache.add(this);
props.addAll(properties.keySet());
PropertyMap primaryParent = getPrimaryParent();
if (primaryParent != null) {
primaryParent.collectPropertyNamesHelper(props, cache);
primaryParent.collectPropertyNames(props);
}
for (PropertyMap p : getSecondaryParents()) {
if (p != null) {
p.collectPropertyNamesHelper(props, cache);
p.collectPropertyNames(props);
}
}
cache.remove(this);
}

boolean removeProperty(String name) {
Expand Down
8 changes: 1 addition & 7 deletions src/com/google/javascript/rhino/jstype/ProxyObjectType.java
Expand Up @@ -44,6 +44,7 @@
import com.google.javascript.rhino.ErrorReporter;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;

import java.util.Collections;

/**
Expand Down Expand Up @@ -258,13 +259,6 @@ public Iterable<ObjectType> getCtorImplementedInterfaces() {
referencedObjType.getCtorImplementedInterfaces();
}

@Override
public Iterable<ObjectType> getCtorExtendedInterfaces() {
return this.referencedObjType == null
? Collections.<ObjectType>emptyList()
: this.referencedObjType.getCtorExtendedInterfaces();
}

@Override
public int hashCode() {
return referencedType.hashCode();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.google.javascript.rhino.jstype.JSTypeRegistry;
import com.google.javascript.rhino.testing.BaseJSTypeTestCase;
import com.google.javascript.rhino.testing.TestErrorReporter;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -1829,70 +1830,6 @@ public void testStructuralInterfacesInExterns() {
testSets(externs, js, js, "{}");
}

public void testPropInParentInterface1() {
String js = LINE_JOINER.join(
"/** @interface */",
"function MyIterable() {}",
"MyIterable.prototype.iterator = function() {};",
"/**",
" * @interface",
" * @extends {MyIterable}",
" * @template T",
" */",
"function MyCollection() {}",
"/**",
" * @constructor",
" * @implements {MyCollection<?>}",
" */",
"function MyAbstractCollection() {}",
"/** @override */",
"MyAbstractCollection.prototype.iterator = function() {};");

testSets(js, "{iterator=[[MyAbstractCollection.prototype, MyIterable.prototype]]}");
}

public void testPropInParentInterface2() {
String js = LINE_JOINER.join(
"/** @interface */",
"function MyIterable() {}",
"MyIterable.prototype.iterator = function() {};",
"/**",
" * @interface",
" * @extends {MyIterable}",
" */",
"function MyCollection() {}",
"/**",
" * @constructor",
" * @implements {MyCollection<?>}",
" */",
"function MyAbstractCollection() {}",
"/** @override */",
"MyAbstractCollection.prototype.iterator = function() {};");

testSets(js, "{iterator=[[MyAbstractCollection.prototype, MyIterable.prototype]]}");
}

public void testPropInParentInterface3() {
String js = LINE_JOINER.join(
"/** @interface */",
"function MyIterable() {}",
"MyIterable.prototype.iterator = function() {};",
"/**",
" * @interface",
" * @extends {MyIterable}",
" */",
"function MyCollection() {}",
"/**",
" * @constructor",
" * @implements {MyCollection}",
" */",
"function MyAbstractCollection() {}",
"/** @override */",
"MyAbstractCollection.prototype.iterator = function() {};");

testSets(js, js, "{iterator=[[MyAbstractCollection.prototype, MyIterable.prototype]]}");
}

public void testErrorOnProtectedProperty() {
testError("function addSingletonGetter(foo) { foo.foobar = 'a'; };",
DisambiguateProperties.Warnings.INVALIDATION);
Expand Down
9 changes: 7 additions & 2 deletions test/com/google/javascript/jscomp/TypeCheckTest.java
Expand Up @@ -31,6 +31,7 @@
import com.google.javascript.rhino.jstype.JSType;
import com.google.javascript.rhino.jstype.JSTypeNative;
import com.google.javascript.rhino.jstype.ObjectType;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -10145,13 +10146,17 @@ public void testInterfaceExtendsLoop() {
}

public void testInterfaceExtendsLoop2() {
testClosureTypes(
testClosureTypesMultipleWarnings(
suppressMissingProperty("foo") +
"/** @record \n * @extends {F} */var G = function() {};" +
"/** @record \n * @extends {G} */var F = function() {};" +
"/** @constructor \n * @implements {F} */var H = function() {};" +
"alert((new H).foo);",
"Parse error. Cycle detected in inheritance chain of type F");
ImmutableList.of(
"extends loop involving F, "
+ "loop: F -> G -> F",
"extends loop involving G, "
+ "loop: G -> F -> G"));
}

public void testConversionFromInterfaceToRecursiveConstructor() {
Expand Down

0 comments on commit 8759434

Please sign in to comment.