Skip to content

Commit b2e8d2d

Browse files
lauraharkercopybara-github
authored andcommitted
Provide a serialized graph of subtypes for ambiguation
This is stored as a separate list of edges instead of a list of supertypes per ObjectType in order to make it easier to store additional graphs in the future, which may need a different definition of "supertype". PiperOrigin-RevId: 326115960
1 parent 596dc20 commit b2e8d2d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/com/google/javascript/jscomp/colors/ObjectColor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.auto.value.AutoValue;
2020
import com.google.common.collect.ImmutableCollection;
21+
import com.google.common.collect.ImmutableList;
2122
import javax.annotation.Nullable;
2223

2324
/**
@@ -57,6 +58,10 @@ public ImmutableCollection<Color> getAlternates() {
5758
@Nullable
5859
public abstract Color getInstanceColor();
5960

61+
// List of other colors directly above this in the subtyping graph for the purposes of property
62+
// (dis)ambiguation.
63+
public abstract ImmutableList<Color> getDisambiguationSupertypes();
64+
6065
@Override
6166
public abstract boolean isInvalidating();
6267

@@ -69,6 +74,8 @@ public abstract static class Builder {
6974

7075
public abstract Builder setInvalidating(boolean value);
7176

77+
public abstract Builder setDisambiguationSupertypes(ImmutableList<Color> supertypes);
78+
7279
public abstract Builder setPrototype(Color prototype);
7380

7481
public abstract Builder setInstanceColor(Color instanceColor);
@@ -77,6 +84,8 @@ public abstract static class Builder {
7784
}
7885

7986
public static Builder builder() {
80-
return new AutoValue_ObjectColor.Builder().setInvalidating(false);
87+
return new AutoValue_ObjectColor.Builder()
88+
.setInvalidating(false)
89+
.setDisambiguationSupertypes(ImmutableList.of());
8190
}
8291
}

src/com/google/javascript/jscomp/testing/ColorSubject.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.truth.FailureMetadata;
2222
import com.google.common.truth.Subject;
2323
import com.google.javascript.jscomp.colors.Color;
24+
import com.google.javascript.jscomp.colors.ObjectColor;
2425
import javax.annotation.Nullable;
2526

2627
/** Subject for {@link Color} */
@@ -75,4 +76,12 @@ public void hasAlternates(Color... alternates) {
7576
// cast to Object[] to suppress warning about varargs vs. non-varargs call confusion
7677
.containsExactly((Object[]) alternates);
7778
}
79+
80+
public void hasDisambiguationSupertypes(Color... alternates) {
81+
isObject();
82+
check("getDirectSupertypes().containsExactly()")
83+
.that(((ObjectColor) actualNonNull()).getDisambiguationSupertypes())
84+
// cast to Object[] to suppress warning about varargs vs. non-varargs call confusion
85+
.containsExactly((Object[]) alternates);
86+
}
7887
}

0 commit comments

Comments
 (0)