Skip to content

Commit 80abe8c

Browse files
authored
Merge pull request swiftlang#21044 from mikeash/anyhashable-to-enum-fix
2 parents 9694851 + 6f7143b commit 80abe8c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,10 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
24362436
cast<StructMetadata>(srcType),
24372437
cast<StructMetadata>(targetType),
24382438
flags);
2439+
} else if (isAnyHashableType(srcType)) {
2440+
// AnyHashable casts for enums.
2441+
return _dynamicCastFromAnyHashable(dest, src, srcType, targetType,
2442+
flags);
24392443
}
24402444
break;
24412445

test/stdlib/AnyHashableCasts.swift.gyb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ testCases = [
8484
("AnyHashable(5)", "Any", "Int", "5"),
8585
("HashableStruct(value: 5)", "HashableStruct", "AnyHashable",
8686
"AnyHashable(HashableStruct(value: 5))"),
87+
("HashableStruct(value: 5)", "AnyHashable", "HashableStruct",
88+
"AnyHashable(HashableStruct(value: 5))"),
8789
("HashableClass(value: 5)", "HashableClass", "AnyHashable",
8890
"AnyHashable(HashableClass(value: 5))"),
91+
("HashableClass(value: 5)", "AnyHashable", "HashableClass",
92+
"AnyHashable(HashableClass(value: 5))"),
8993
("HashableEnum.value(5)", "HashableEnum", "AnyHashable",
9094
"AnyHashable(HashableEnum.value(5))"),
95+
("HashableEnum.value(5)", "AnyHashable", "HashableEnum",
96+
"AnyHashable(HashableEnum.value(5))"),
9197
]
9298
}%
9399

0 commit comments

Comments
 (0)