Skip to content

Commit c42f4ea

Browse files
committed
Remove a latent Optional<Type> from independent expr checking
1 parent 8249593 commit c42f4ea

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4650,9 +4650,9 @@ static bool diagnoseImplicitSelfErrors(Expr *fnExpr, Expr *argExpr,
46504650
ConcreteDeclRef ref = nullptr;
46514651
auto typeResult =
46524652
TC.getTypeOfExpressionWithoutApplying(el, CS.DC, ref);
4653-
if (!typeResult.hasValue())
4653+
if (!typeResult)
46544654
return false;
4655-
elts.push_back(typeResult.getValue());
4655+
elts.push_back(typeResult);
46564656
}
46574657

46584658
argType = TupleType::get(elts, CS.getASTContext());
@@ -6387,12 +6387,12 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
63876387
"unexpected declaration reference");
63886388

63896389
ConcreteDeclRef decl = nullptr;
6390-
Optional<Type> type = CS.TC.getTypeOfExpressionWithoutApplying(
6390+
Type type = CS.TC.getTypeOfExpressionWithoutApplying(
63916391
fnExpr, CS.DC, decl, FreeTypeVariableBinding::UnresolvedType,
63926392
&listener);
63936393

6394-
if (type.hasValue())
6395-
fnType = getFuncType(type.getValue());
6394+
if (type)
6395+
fnType = getFuncType(type);
63966396
} else {
63976397
fnExpr = typeCheckChildIndependently(callExpr->getFn(), Type(),
63986398
CTP_CalleeResult, TCC_ForceRecheck,
@@ -7336,7 +7336,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
73367336
auto type = CS.TC.getTypeOfExpressionWithoutApplying(
73377337
closure, CS.DC, decl, FreeTypeVariableBinding::Disallow);
73387338

7339-
if (type && resultTypeProcessor(*type, expectedResultType))
7339+
if (type && resultTypeProcessor(type, expectedResultType))
73407340
return true;
73417341
}
73427342

@@ -7821,7 +7821,7 @@ bool FailureDiagnosis::visitKeyPathExpr(KeyPathExpr *KPE) {
78217821
&listener);
78227822

78237823
if (derivedType) {
7824-
if (auto *BGT = (*derivedType)->getAs<BoundGenericClassType>()) {
7824+
if (auto *BGT = derivedType->getAs<BoundGenericClassType>()) {
78257825
auto derivedValueType = BGT->getGenericArgs().back();
78267826
if (!CS.TC.isConvertibleTo(valueType, derivedValueType, CS.DC)) {
78277827
diagnose(KPE->getLoc(),
@@ -8982,7 +8982,7 @@ diagnoseAmbiguousMultiStatementClosure(ClosureExpr *closure) {
89828982
auto type = CS.TC.getTypeOfExpressionWithoutApplying(
89838983
resultExpr, CS.DC, decl, FreeTypeVariableBinding::UnresolvedType);
89848984
if (type)
8985-
resultType = type.getValue();
8985+
resultType = type;
89868986
}
89878987

89888988
// If we found a type, presuppose it was the intended result and insert a

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
18141814
return cs.getType(expr);
18151815
}
18161816

1817-
Optional<Type> TypeChecker::
1817+
Type TypeChecker::
18181818
getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
18191819
ConcreteDeclRef &referencedDecl,
18201820
FreeTypeVariableBinding allowFreeTypeVariables,
@@ -1843,7 +1843,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
18431843
allowFreeTypeVariables, listener, cs, viable,
18441844
TypeCheckExprFlags::SuppressDiagnostics)) {
18451845
recoverOriginalType();
1846-
return None;
1846+
return Type();
18471847
}
18481848

18491849
// Get the expression's simplified type.
@@ -1856,7 +1856,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
18561856

18571857
if (exprType->hasError()) {
18581858
recoverOriginalType();
1859-
return None;
1859+
return Type();
18601860
}
18611861

18621862
// Dig the declaration out of the solution.

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,9 @@ class TypeChecker final : public LazyResolver {
15931593
/// events in the type checking of this expression, and which can introduce
15941594
/// additional constraints.
15951595
///
1596-
/// \returns the type of \p expr on success, None otherwise.
1596+
/// \returns the type of \p expr on success, Type() otherwise.
15971597
/// FIXME: expr may still be modified...
1598-
Optional<Type> getTypeOfExpressionWithoutApplying(
1598+
Type getTypeOfExpressionWithoutApplying(
15991599
Expr *&expr, DeclContext *dc,
16001600
ConcreteDeclRef &referencedDecl,
16011601
FreeTypeVariableBinding allowFreeTypeVariables =

0 commit comments

Comments
 (0)