File tree Expand file tree Collapse file tree 3 files changed +18
-16
lines changed Expand file tree Collapse file tree 3 files changed +18
-16
lines changed Original file line number Diff line number Diff line change @@ -5919,6 +5919,13 @@ class AbstractStorageDecl : public ValueDecl {
5919
5919
// / Return the interface type of the stored value.
5920
5920
Type getValueInterfaceType () const ;
5921
5921
5922
+ // / Retrieve the source range of the variable type, or an invalid range if the
5923
+ // / variable's type is not explicitly written in the source.
5924
+ // /
5925
+ // / Only for use in diagnostics. It is not always possible to always
5926
+ // / precisely point to the variable type because of type aliases.
5927
+ SourceRange getTypeSourceRangeForDiagnostics () const ;
5928
+
5922
5929
// / Determine how this storage is implemented.
5923
5930
StorageImplInfo getImplInfo () const ;
5924
5931
@@ -6353,13 +6360,6 @@ class VarDecl : public AbstractStorageDecl {
6353
6360
// / and not just getInterfaceType().
6354
6361
Type getTypeInContext () const ;
6355
6362
6356
- // / Retrieve the source range of the variable type, or an invalid range if the
6357
- // / variable's type is not explicitly written in the source.
6358
- // /
6359
- // / Only for use in diagnostics. It is not always possible to always
6360
- // / precisely point to the variable type because of type aliases.
6361
- SourceRange getTypeSourceRangeForDiagnostics () const ;
6362
-
6363
6363
// / Determine the mutability of this variable declaration when
6364
6364
// / accessed from a given declaration context.
6365
6365
StorageMutability mutability (
Original file line number Diff line number Diff line change @@ -7874,14 +7874,19 @@ SourceRange VarDecl::getSourceRange() const {
7874
7874
return getNameLoc ();
7875
7875
}
7876
7876
7877
- SourceRange VarDecl::getTypeSourceRangeForDiagnostics () const {
7877
+ SourceRange AbstractStorageDecl::getTypeSourceRangeForDiagnostics () const {
7878
+ // Subscripts always have an explicitly-written type.
7879
+ if (auto *SD = dyn_cast<SubscriptDecl>(this ))
7880
+ return SD->getElementTypeSourceRange ();
7881
+
7878
7882
// For a parameter, map back to its parameter to get the TypeLoc.
7879
7883
if (auto *PD = dyn_cast<ParamDecl>(this )) {
7880
7884
if (auto typeRepr = PD->getTypeRepr ())
7881
7885
return typeRepr->getSourceRange ();
7882
7886
}
7883
-
7884
- Pattern *Pat = getParentPattern ();
7887
+
7888
+ auto *VD = cast<VarDecl>(this );
7889
+ Pattern *Pat = VD->getParentPattern ();
7885
7890
if (!Pat || Pat->isImplicit ())
7886
7891
return SourceRange ();
7887
7892
Original file line number Diff line number Diff line change @@ -3724,15 +3724,12 @@ bool AssociatedTypeInference::diagnoseNoSolutions(
3724
3724
failed.Result .getKind () != CheckTypeWitnessResult::Superclass) {
3725
3725
Type resultType;
3726
3726
SourceRange typeRange;
3727
- if (auto *var = dyn_cast<VarDecl >(failed.Witness )) {
3728
- resultType = var ->getValueInterfaceType ();
3729
- typeRange = var ->getTypeSourceRangeForDiagnostics ();
3727
+ if (auto *storage = dyn_cast<AbstractStorageDecl >(failed.Witness )) {
3728
+ resultType = storage ->getValueInterfaceType ();
3729
+ typeRange = storage ->getTypeSourceRangeForDiagnostics ();
3730
3730
} else if (auto *func = dyn_cast<FuncDecl>(failed.Witness )) {
3731
3731
resultType = func->getResultInterfaceType ();
3732
3732
typeRange = func->getResultTypeSourceRange ();
3733
- } else if (auto *subscript = dyn_cast<SubscriptDecl>(failed.Witness )) {
3734
- resultType = subscript->getElementInterfaceType ();
3735
- typeRange = subscript->getElementTypeSourceRange ();
3736
3733
}
3737
3734
3738
3735
// If the type witness was inferred from an existential
You can’t perform that action at this time.
0 commit comments