Skip to content

Commit 365511c

Browse files
committed
[Constraint system] Remove TypeCheckExprFlags::ExpressionTypeMustBeOptional.
This result can be computed from the pattern of an initializer expression, so do that instead.
1 parent 52da2d6 commit 365511c

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

lib/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,13 @@ class SolutionApplicationTarget {
12521252
return expression.pattern;
12531253
}
12541254

1255+
/// Whether this is an initialization for an Optional.Some pattern.
1256+
bool isOptionalSomePatternInit() const {
1257+
return kind == Kind::expression &&
1258+
expression.contextualPurpose == CTP_Initialization &&
1259+
isa<OptionalSomePattern>(expression.pattern);
1260+
}
1261+
12551262
/// Whether the contextual type is only a hint, rather than a type
12561263
bool contextualTypeIsOnlyAHint(bool isOpaqueReturnType) const;
12571264

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ TypeChecker::typeCheckExpression(
21502150

21512151
Type convertTo = convertType.getType();
21522152

2153-
if (options.contains(TypeCheckExprFlags::ExpressionTypeMustBeOptional)) {
2153+
if (target.isOptionalSomePatternInit()) {
21542154
assert(!convertTo && "convertType and type check options conflict");
21552155
auto *convertTypeLocator =
21562156
cs.getConstraintLocator(expr, LocatorPathElt::ContextualType());
@@ -2669,24 +2669,12 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
26692669
if (!initializer)
26702670
return true;
26712671

2672-
TypeLoc contextualType;
2673-
auto contextualPurpose = CTP_Unused;
2674-
TypeCheckExprOptions flags = None;
2675-
2676-
// Set the contextual purpose even if the pattern doesn't have a type so
2677-
// if there's an error we can use that information to inform diagnostics.
2678-
contextualPurpose = CTP_Initialization;
2679-
2680-
if (isa<OptionalSomePattern>(pattern)) {
2681-
flags |= TypeCheckExprFlags::ExpressionTypeMustBeOptional;
2682-
}
2683-
26842672
// Type-check the initializer.
26852673
auto target = SolutionApplicationTarget::forInitialization(
26862674
initializer, patternType, pattern);
26872675
bool unresolvedTypeExprs = false;
26882676
auto resultTarget = typeCheckExpression(target, DC, unresolvedTypeExprs,
2689-
flags, &listener);
2677+
None, &listener);
26902678

26912679
if (resultTarget) {
26922680
initializer = resultTarget->getAsExpr();

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ enum class TypeCheckExprFlags {
176176
/// not affect type checking itself.
177177
IsExprStmt = 0x20,
178178

179-
/// If set, a conversion constraint should be specified so that the result of
180-
/// the expression is an optional type.
181-
ExpressionTypeMustBeOptional = 0x200,
182-
183179
/// FIXME(diagnostics): Once diagnostics are completely switched to new
184180
/// framework, this flag could be removed as obsolete.
185181
///

0 commit comments

Comments
 (0)