Skip to content

Commit 2968b03

Browse files
authored
Merge pull request #11048 from CodaFi/optional-illusion
[NFC] Adjust return type of getTypeOfExpressionWithoutApplying
2 parents 707e6de + c42f4ea commit 2968b03

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
@@ -4651,9 +4651,9 @@ static bool diagnoseImplicitSelfErrors(Expr *fnExpr, Expr *argExpr,
46514651
ConcreteDeclRef ref = nullptr;
46524652
auto typeResult =
46534653
TC.getTypeOfExpressionWithoutApplying(el, CS.DC, ref);
4654-
if (!typeResult.hasValue())
4654+
if (!typeResult)
46554655
return false;
4656-
elts.push_back(typeResult.getValue());
4656+
elts.push_back(typeResult);
46574657
}
46584658

46594659
argType = TupleType::get(elts, CS.getASTContext());
@@ -6389,12 +6389,12 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
63896389
"unexpected declaration reference");
63906390

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

6396-
if (type.hasValue())
6397-
fnType = getFuncType(type.getValue());
6396+
if (type)
6397+
fnType = getFuncType(type);
63986398
} else {
63996399
fnExpr = typeCheckChildIndependently(callExpr->getFn(), Type(),
64006400
CTP_CalleeResult, TCC_ForceRecheck,
@@ -7338,7 +7338,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
73387338
auto type = CS.TC.getTypeOfExpressionWithoutApplying(
73397339
closure, CS.DC, decl, FreeTypeVariableBinding::Disallow);
73407340

7341-
if (type && resultTypeProcessor(*type, expectedResultType))
7341+
if (type && resultTypeProcessor(type, expectedResultType))
73427342
return true;
73437343
}
73447344

@@ -7825,7 +7825,7 @@ bool FailureDiagnosis::visitKeyPathExpr(KeyPathExpr *KPE) {
78257825
&listener);
78267826

78277827
if (derivedType) {
7828-
if (auto *BGT = (*derivedType)->getAs<BoundGenericClassType>()) {
7828+
if (auto *BGT = derivedType->getAs<BoundGenericClassType>()) {
78297829
auto derivedValueType = BGT->getGenericArgs().back();
78307830
if (!CS.TC.isConvertibleTo(valueType, derivedValueType, CS.DC)) {
78317831
diagnose(KPE->getLoc(),
@@ -8986,7 +8986,7 @@ diagnoseAmbiguousMultiStatementClosure(ClosureExpr *closure) {
89868986
auto type = CS.TC.getTypeOfExpressionWithoutApplying(
89878987
resultExpr, CS.DC, decl, FreeTypeVariableBinding::UnresolvedType);
89888988
if (type)
8989-
resultType = type.getValue();
8989+
resultType = type;
89908990
}
89918991

89928992
// 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
@@ -1820,7 +1820,7 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
18201820
return cs.getType(expr);
18211821
}
18221822

1823-
Optional<Type> TypeChecker::
1823+
Type TypeChecker::
18241824
getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
18251825
ConcreteDeclRef &referencedDecl,
18261826
FreeTypeVariableBinding allowFreeTypeVariables,
@@ -1849,7 +1849,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
18491849
allowFreeTypeVariables, listener, cs, viable,
18501850
TypeCheckExprFlags::SuppressDiagnostics)) {
18511851
recoverOriginalType();
1852-
return None;
1852+
return Type();
18531853
}
18541854

18551855
// Get the expression's simplified type.
@@ -1862,7 +1862,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
18621862

18631863
if (exprType->hasError()) {
18641864
recoverOriginalType();
1865-
return None;
1865+
return Type();
18661866
}
18671867

18681868
// 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
@@ -1592,9 +1592,9 @@ class TypeChecker final : public LazyResolver {
15921592
/// events in the type checking of this expression, and which can introduce
15931593
/// additional constraints.
15941594
///
1595-
/// \returns the type of \p expr on success, None otherwise.
1595+
/// \returns the type of \p expr on success, Type() otherwise.
15961596
/// FIXME: expr may still be modified...
1597-
Optional<Type> getTypeOfExpressionWithoutApplying(
1597+
Type getTypeOfExpressionWithoutApplying(
15981598
Expr *&expr, DeclContext *dc,
15991599
ConcreteDeclRef &referencedDecl,
16001600
FreeTypeVariableBinding allowFreeTypeVariables =

0 commit comments

Comments
 (0)