Tweak the display of the type of an empty Map (#2590)

Fixes #2247
Closes #2252
This commit is contained in:
Erik Arvidsson
2016-09-16 17:48:47 -07:00
committed by GitHub
parent ee1db61bba
commit e3bea0f274
5 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -81,6 +81,6 @@ func (s *ThreeWaySetMergeSuite) TestThreeWayMerge_Refs() {
}
func (s *ThreeWaySetMergeSuite) TestThreeWayMerge_ImmediateConflict() {
s.tryThreeWayConflict(types.NewMap(), s.create(ss1b), s.create(ss1), "Cannot merge Map<, > with "+s.typeStr)
s.tryThreeWayConflict(types.NewMap(), s.create(ss1b), s.create(ss1), "Cannot merge Map<> with "+s.typeStr)
s.tryThreeWayConflict(s.create(ss1b), types.NewMap(), s.create(ss1), "Cannot merge "+s.typeStr)
}
+5
View File
@@ -245,6 +245,11 @@ func (w *hrsWriter) writeType(t *Type, parentStructTypes []*Type) {
w.write(KindToString[t.Kind()])
w.write("<")
for i, et := range t.Desc.(CompoundDesc).ElemTypes {
if et.Kind() == UnionKind && len(et.Desc.(CompoundDesc).ElemTypes) == 0 {
// If one of the element types is an empty union all the other element types must
// also be empty union types.
break
}
if i != 0 {
w.write(", ")
}
+1 -1
View File
@@ -406,7 +406,7 @@ func TestEmptyCollections(t *testing.T) {
c := MakeMapType(BlobType, NumberType)
assertWriteTaggedHRSEqual(t, "Type(Map<Blob, Number>)", c)
d := NewMap()
assertWriteTaggedHRSEqual(t, "Map<, >({})", d)
assertWriteTaggedHRSEqual(t, "Map<>({})", d)
e := MakeSetType(StringType)
assertWriteTaggedHRSEqual(t, "Type(Set<String>)", e)
f := NewSet()
@@ -56,6 +56,8 @@ suite('Encode human readable types', () => {
assertWriteType('', makeUnionType([]));
assertWriteType('List<Number | String>', makeListType(makeUnionType([numberType, stringType])));
assertWriteType('List<>', makeListType(makeUnionType([])));
assertWriteType('Set<>', makeSetType(makeUnionType([])));
assertWriteType('Map<>', makeMapType(makeUnionType([]), makeUnionType([])));
});
test('struct', () => {
+5
View File
@@ -88,6 +88,11 @@ export class TypeWriter {
this._w.write('<');
invariant(t.desc instanceof CompoundDesc);
t.desc.elemTypes.forEach((t, i) => {
if (t.kind === Kind.Union && t.desc.elemTypes.length === 0) {
// If one of the element types is an empty union all the other element types must also
// be empty union types.
return;
}
if (i !== 0) {
this._w.write(', ');
}