Skip to content

Commit 08bfba7

Browse files
committed
[Constraint system] Add conversion constraint for typed patterns.
For typed patterns, the sub pattern type must be convertible to the type provided to the pattern.
1 parent bea9d06 commit 08bfba7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,13 +2252,19 @@ namespace {
22522252

22532253
case PatternKind::Typed: {
22542254
// FIXME: Need a better locator for a pattern as a base.
2255+
// Compute the type ascribed to the pattern.
22552256
auto contextualPattern =
22562257
ContextualPattern::forRawPattern(pattern, CurDC);
22572258
Type type = TypeChecker::typeCheckPattern(contextualPattern);
22582259
Type openedType = CS.openUnboundGenericType(type, locator);
22592260

2260-
// For a typed pattern, simply return the opened type of the pattern.
2261-
// FIXME: Error recovery if the type is an error type?
2261+
// Determine the subpattern type. It will be convertible to the
2262+
// ascribed type.
2263+
Type subPatternType =
2264+
getTypeForPattern(
2265+
cast<TypedPattern>(pattern)->getSubPattern(), locator);
2266+
CS.addConstraint(
2267+
ConstraintKind::Conversion, subPatternType, openedType, locator);
22622268
return setType(openedType);
22632269
}
22642270

0 commit comments

Comments
 (0)