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 @@ -5892,6 +5892,13 @@ class AbstractStorageDecl : public ValueDecl {
5892
5892
// / Return the interface type of the stored value.
5893
5893
Type getValueInterfaceType () const ;
5894
5894
5895
+ // / Retrieve the source range of the variable type, or an invalid range if the
5896
+ // / variable's type is not explicitly written in the source.
5897
+ // /
5898
+ // / Only for use in diagnostics. It is not always possible to always
5899
+ // / precisely point to the variable type because of type aliases.
5900
+ SourceRange getTypeSourceRangeForDiagnostics () const ;
5901
+
5895
5902
// / Determine how this storage is implemented.
5896
5903
StorageImplInfo getImplInfo () const ;
5897
5904
@@ -6326,13 +6333,6 @@ class VarDecl : public AbstractStorageDecl {
6326
6333
// / and not just getInterfaceType().
6327
6334
Type getTypeInContext () const ;
6328
6335
6329
- // / Retrieve the source range of the variable type, or an invalid range if the
6330
- // / variable's type is not explicitly written in the source.
6331
- // /
6332
- // / Only for use in diagnostics. It is not always possible to always
6333
- // / precisely point to the variable type because of type aliases.
6334
- SourceRange getTypeSourceRangeForDiagnostics () const ;
6335
-
6336
6336
// / Determine the mutability of this variable declaration when
6337
6337
// / accessed from a given declaration context.
6338
6338
StorageMutability mutability (
Original file line number Diff line number Diff line change @@ -7758,14 +7758,19 @@ SourceRange VarDecl::getSourceRange() const {
7758
7758
return getNameLoc ();
7759
7759
}
7760
7760
7761
- SourceRange VarDecl::getTypeSourceRangeForDiagnostics () const {
7761
+ SourceRange AbstractStorageDecl::getTypeSourceRangeForDiagnostics () const {
7762
+ // Subscripts always have an explicitly-written type.
7763
+ if (auto *SD = dyn_cast<SubscriptDecl>(this ))
7764
+ return SD->getElementTypeSourceRange ();
7765
+
7762
7766
// For a parameter, map back to its parameter to get the TypeLoc.
7763
7767
if (auto *PD = dyn_cast<ParamDecl>(this )) {
7764
7768
if (auto typeRepr = PD->getTypeRepr ())
7765
7769
return typeRepr->getSourceRange ();
7766
7770
}
7767
-
7768
- Pattern *Pat = getParentPattern ();
7771
+
7772
+ auto *VD = cast<VarDecl>(this );
7773
+ Pattern *Pat = VD->getParentPattern ();
7769
7774
if (!Pat || Pat->isImplicit ())
7770
7775
return SourceRange ();
7771
7776
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