Skip to content

Commit 50d0508

Browse files
committed
[ConstraintSystem] Add a new contextual type purpose - expression pattern
This makes it possible to associate expression with its parent pattern.
1 parent 49d397c commit 50d0508

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ enum ContextualTypePurpose : uint8_t {
8585
CTP_ComposedPropertyWrapper, ///< Composed wrapper type expected to match
8686
///< former 'wrappedValue' type
8787

88+
CTP_ExprPattern, ///< `~=` operator application associated with expression
89+
/// pattern.
90+
8891
CTP_CannotFail, ///< Conversion can never fail. abort() if it does.
8992
};
9093

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8936,6 +8936,7 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
89368936
case CTP_Unused:
89378937
case CTP_CaseStmt:
89388938
case CTP_ReturnStmt:
8939+
case CTP_ExprPattern:
89398940
case swift::CTP_ReturnSingleExpr:
89408941
case swift::CTP_YieldByValue:
89418942
case swift::CTP_YieldByReference:

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ Optional<Diag<Type, Type>> GenericArgumentsMismatchFailure::getDiagnosticFor(
705705
case CTP_YieldByReference:
706706
case CTP_CalleeResult:
707707
case CTP_EnumCaseRawValue:
708+
case CTP_ExprPattern:
708709
break;
709710
}
710711
return None;
@@ -2533,6 +2534,7 @@ getContextualNilDiagnostic(ContextualTypePurpose CTP) {
25332534
case CTP_YieldByReference:
25342535
case CTP_WrappedProperty:
25352536
case CTP_ComposedPropertyWrapper:
2537+
case CTP_ExprPattern:
25362538
return None;
25372539

25382540
case CTP_EnumCaseRawValue:
@@ -3296,6 +3298,7 @@ ContextualFailure::getDiagnosticFor(ContextualTypePurpose context,
32963298
case CTP_CannotFail:
32973299
case CTP_YieldByReference:
32983300
case CTP_CalleeResult:
3301+
case CTP_ExprPattern:
32993302
break;
33003303
}
33013304
return None;

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12944,6 +12944,7 @@ void ConstraintSystem::addContextualConversionConstraint(
1294412944
case CTP_ForEachStmt:
1294512945
case CTP_WrappedProperty:
1294612946
case CTP_ComposedPropertyWrapper:
12947+
case CTP_ExprPattern:
1294712948
break;
1294812949
}
1294912950

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5873,6 +5873,7 @@ bool SolutionApplicationTarget::contextualTypeIsOnlyAHint() const {
58735873
case CTP_WrappedProperty:
58745874
case CTP_ComposedPropertyWrapper:
58755875
case CTP_CannotFail:
5876+
case CTP_ExprPattern:
58765877
return false;
58775878
}
58785879
llvm_unreachable("invalid contextual type");

0 commit comments

Comments
 (0)