@@ -6178,10 +6178,13 @@ void SubscriptDecl::setIndices(ParameterList *p) {
6178
6178
}
6179
6179
6180
6180
Type SubscriptDecl::getElementInterfaceType () const {
6181
- auto elementTy = getInterfaceType ();
6182
- if (elementTy->is <ErrorType>())
6183
- return elementTy;
6184
- return elementTy->castTo <AnyFunctionType>()->getResult ();
6181
+ // Force type checking of the result TypeLoc.
6182
+ (void ) getInterfaceType ();
6183
+
6184
+ auto type = getElementTypeLoc ().getType ();
6185
+ if (!type)
6186
+ return TupleType::getEmpty (getASTContext ());
6187
+ return type;
6185
6188
}
6186
6189
6187
6190
void SubscriptDecl::computeType () {
@@ -6629,18 +6632,7 @@ void AbstractFunctionDecl::computeType(AnyFunctionType::ExtInfo info) {
6629
6632
}
6630
6633
6631
6634
} else if (auto ctor = dyn_cast<ConstructorDecl>(this )) {
6632
- auto *dc = ctor->getDeclContext ();
6633
-
6634
- if (hasSelf) {
6635
- if (!dc->isTypeContext ())
6636
- resultTy = ErrorType::get (ctx);
6637
- else
6638
- resultTy = dc->getSelfInterfaceType ();
6639
- }
6640
-
6641
- // Adjust result type for failability.
6642
- if (ctor->isFailable ())
6643
- resultTy = OptionalType::get (resultTy);
6635
+ resultTy = ctor->getResultInterfaceType ();
6644
6636
} else {
6645
6637
assert (isa<DestructorDecl>(this ));
6646
6638
resultTy = TupleType::getEmpty (ctx);
@@ -6893,14 +6885,13 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
6893
6885
}
6894
6886
6895
6887
Type FuncDecl::getResultInterfaceType () const {
6896
- Type resultTy = getInterfaceType ();
6897
- if (resultTy.isNull () || resultTy->is <ErrorType>())
6898
- return resultTy;
6899
-
6900
- if (hasImplicitSelfDecl ())
6901
- resultTy = resultTy->castTo <AnyFunctionType>()->getResult ();
6888
+ // Force type checking of the result TypeLoc.
6889
+ (void ) getInterfaceType ();
6902
6890
6903
- return resultTy->castTo <AnyFunctionType>()->getResult ();
6891
+ auto resultTy = getBodyResultTypeLoc ().getType ();
6892
+ if (!resultTy)
6893
+ return TupleType::getEmpty (getASTContext ());
6894
+ return resultTy;
6904
6895
}
6905
6896
6906
6897
bool FuncDecl::isUnaryOperator () const {
@@ -7153,10 +7144,19 @@ SourceRange ConstructorDecl::getSourceRange() const {
7153
7144
}
7154
7145
7155
7146
Type ConstructorDecl::getResultInterfaceType () const {
7156
- Type ArgTy = getInterfaceType ();
7157
- ArgTy = ArgTy->castTo <AnyFunctionType>()->getResult ();
7158
- ArgTy = ArgTy->castTo <AnyFunctionType>()->getResult ();
7159
- return ArgTy;
7147
+ Type resultTy;
7148
+
7149
+ auto *dc = getDeclContext ();
7150
+ if (!dc->isTypeContext ())
7151
+ resultTy = ErrorType::get (getASTContext ());
7152
+ else
7153
+ resultTy = dc->getSelfInterfaceType ();
7154
+
7155
+ // Adjust result type for failability.
7156
+ if (isFailable ())
7157
+ return OptionalType::get (resultTy);
7158
+
7159
+ return resultTy;
7160
7160
}
7161
7161
7162
7162
Type ConstructorDecl::getInitializerInterfaceType () {
0 commit comments