Don't trap when creating a Set from a literal with duplicate elements

rdar://problem/19178760

Swift SVN r23791
This commit is contained in:
David Farler
2014-12-08 23:09:04 +00:00
parent 933ac28760
commit 324411a44b
3 changed files with 31 additions and 33 deletions

View File

@@ -1882,11 +1882,16 @@ internal struct _Native${Self}Storage<${TypeParametersDecl}> :
%if Self == 'Set':
var count = 0
for key in elements {
var (i, found) = nativeStorage._find(key, nativeStorage._bucket(key))
_precondition(!found, "${Self} literal contains duplicate keys")
if found {
continue
}
nativeStorage[i.offset] = Element(key: key)
++count
}
nativeStorage.count = count
%elif Self == 'Dictionary':
@@ -1895,10 +1900,10 @@ internal struct _Native${Self}Storage<${TypeParametersDecl}> :
_precondition(!found, "${Self} literal contains duplicate keys")
nativeStorage[i.offset] = Element(key: key, value: value)
}
nativeStorage.count = elements.count
%end
nativeStorage.count = elements.count
return nativeStorage
}
}