From 8759434583175dae0679013a6ea7f5f11a5d5b1d Mon Sep 17 00:00:00 2001 From: dimvar Date: Thu, 21 Jul 2016 08:50:23 -0700 Subject: [PATCH] Rollback of "Fix bug in DisambiguateProperties involving generic interfac..." 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 --- .../javascript/rhino/jstype/PropertyMap.java | 23 ++----- .../rhino/jstype/ProxyObjectType.java | 8 +-- .../jscomp/DisambiguatePropertiesTest.java | 65 +------------------ .../javascript/jscomp/TypeCheckTest.java | 9 ++- 4 files changed, 13 insertions(+), 92 deletions(-) diff --git a/src/com/google/javascript/rhino/jstype/PropertyMap.java b/src/com/google/javascript/rhino/jstype/PropertyMap.java index f2fcfa68bbc..d3a4301811e 100644 --- a/src/com/google/javascript/rhino/jstype/PropertyMap.java +++ b/src/com/google/javascript/rhino/jstype/PropertyMap.java @@ -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; @@ -165,29 +163,16 @@ Set getOwnPropertyNames() { } void collectPropertyNames(Set props) { - Set identitySet = Sets.newIdentityHashSet(); - collectPropertyNamesHelper(props, identitySet); - } - - // The interface inheritance chain can have cycles. - // Use cache to avoid stack overflow. - private void collectPropertyNamesHelper( - Set props, Set 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) { diff --git a/src/com/google/javascript/rhino/jstype/ProxyObjectType.java b/src/com/google/javascript/rhino/jstype/ProxyObjectType.java index aa826c5ec19..df25ccff9c9 100644 --- a/src/com/google/javascript/rhino/jstype/ProxyObjectType.java +++ b/src/com/google/javascript/rhino/jstype/ProxyObjectType.java @@ -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; /** @@ -258,13 +259,6 @@ public Iterable getCtorImplementedInterfaces() { referencedObjType.getCtorImplementedInterfaces(); } - @Override - public Iterable getCtorExtendedInterfaces() { - return this.referencedObjType == null - ? Collections.emptyList() - : this.referencedObjType.getCtorExtendedInterfaces(); - } - @Override public int hashCode() { return referencedType.hashCode(); diff --git a/test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java b/test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java index 5f970117a9f..af91dc007cd 100644 --- a/test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java +++ b/test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java @@ -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; @@ -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); diff --git a/test/com/google/javascript/jscomp/TypeCheckTest.java b/test/com/google/javascript/jscomp/TypeCheckTest.java index 730ec512987..87356ab8c77 100644 --- a/test/com/google/javascript/jscomp/TypeCheckTest.java +++ b/test/com/google/javascript/jscomp/TypeCheckTest.java @@ -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; @@ -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() {