@@ -1728,12 +1728,18 @@ namespace {
17281728 LocatorPathElt::getTupleElement (index++)));
17291729 }
17301730
1731+ // The array element type defaults to 'Any'.
1732+ if (auto elementTypeVar = arrayElementTy->getAs <TypeVariableType>()) {
1733+ CS.addConstraint (ConstraintKind::Defaultable, arrayElementTy,
1734+ tc.Context .TheAnyType , locator);
1735+ CS.ArrayElementTypeVariables [expr] = elementTypeVar;
1736+ }
1737+
17311738 return arrayTy;
17321739 }
17331740
17341741 static bool isMergeableValueKind (Expr *expr) {
1735- return isa<CollectionExpr>(expr) ||
1736- isa<StringLiteralExpr>(expr) || isa<IntegerLiteralExpr>(expr) ||
1742+ return isa<StringLiteralExpr>(expr) || isa<IntegerLiteralExpr>(expr) ||
17371743 isa<FloatLiteralExpr>(expr);
17381744 }
17391745
@@ -1811,16 +1817,22 @@ namespace {
18111817 auto keyTyvar2 = tty2->getElementTypes ()[0 ]->
18121818 getAs<TypeVariableType>();
18131819
1814- mergedKey = mergeRepresentativeEquivalenceClasses (CS,
1820+ auto keyExpr1 = cast<TupleExpr>(element1)->getElements ()[0 ];
1821+ auto keyExpr2 = cast<TupleExpr>(element2)->getElements ()[0 ];
1822+
1823+ if (keyExpr1->getKind () == keyExpr2->getKind () &&
1824+ isMergeableValueKind (keyExpr1)) {
1825+ mergedKey = mergeRepresentativeEquivalenceClasses (CS,
18151826 keyTyvar1, keyTyvar2);
1827+ }
18161828
18171829 auto valueTyvar1 = tty1->getElementTypes ()[1 ]->
18181830 getAs<TypeVariableType>();
18191831 auto valueTyvar2 = tty2->getElementTypes ()[1 ]->
18201832 getAs<TypeVariableType>();
18211833
1822- auto elemExpr1 = dyn_cast <TupleExpr>(element1)->getElements ()[1 ];
1823- auto elemExpr2 = dyn_cast <TupleExpr>(element2)->getElements ()[1 ];
1834+ auto elemExpr1 = cast <TupleExpr>(element1)->getElements ()[1 ];
1835+ auto elemExpr2 = cast <TupleExpr>(element2)->getElements ()[1 ];
18241836
18251837 if (elemExpr1->getKind () == elemExpr2->getKind () &&
18261838 isMergeableValueKind (elemExpr1)) {
@@ -1849,6 +1861,26 @@ namespace {
18491861 LocatorPathElt::getTupleElement (index++)));
18501862 }
18511863
1864+ // The dictionary key type defaults to 'AnyHashable'.
1865+ auto keyTypeVar = dictionaryKeyTy->getAs <TypeVariableType>();
1866+ if (keyTypeVar && tc.Context .getAnyHashableDecl ()) {
1867+ auto anyHashable = tc.Context .getAnyHashableDecl ();
1868+ tc.validateDecl (anyHashable);
1869+ CS.addConstraint (ConstraintKind::Defaultable, dictionaryKeyTy,
1870+ anyHashable->getDeclaredInterfaceType (), locator);
1871+ }
1872+
1873+ // The dictionary value type defaults to 'Any'.
1874+ auto valueTypeVar = dictionaryValueTy->getAs <TypeVariableType>();
1875+ if (valueTypeVar) {
1876+ CS.addConstraint (ConstraintKind::Defaultable, dictionaryValueTy,
1877+ tc.Context .TheAnyType , locator);
1878+ }
1879+
1880+ // Record key/value type variables.
1881+ if (keyTypeVar || valueTypeVar)
1882+ CS.DictionaryElementTypeVariables [expr] = { keyTypeVar, valueTypeVar };
1883+
18521884 return dictionaryTy;
18531885 }
18541886
0 commit comments