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 @@ -5947,6 +5947,13 @@ class AbstractStorageDecl : public ValueDecl {
5947
5947
// / Return the interface type of the stored value.
5948
5948
Type getValueInterfaceType () const ;
5949
5949
5950
+ // / Retrieve the source range of the variable type, or an invalid range if the
5951
+ // / variable's type is not explicitly written in the source.
5952
+ // /
5953
+ // / Only for use in diagnostics. It is not always possible to always
5954
+ // / precisely point to the variable type because of type aliases.
5955
+ SourceRange getTypeSourceRangeForDiagnostics () const ;
5956
+
5950
5957
// / Determine how this storage is implemented.
5951
5958
StorageImplInfo getImplInfo () const ;
5952
5959
@@ -6381,13 +6388,6 @@ class VarDecl : public AbstractStorageDecl {
6381
6388
// / and not just getInterfaceType().
6382
6389
Type getTypeInContext () const ;
6383
6390
6384
- // / Retrieve the source range of the variable type, or an invalid range if the
6385
- // / variable's type is not explicitly written in the source.
6386
- // /
6387
- // / Only for use in diagnostics. It is not always possible to always
6388
- // / precisely point to the variable type because of type aliases.
6389
- SourceRange getTypeSourceRangeForDiagnostics () const ;
6390
-
6391
6391
// / Determine the mutability of this variable declaration when
6392
6392
// / accessed from a given declaration context.
6393
6393
StorageMutability mutability (
Original file line number Diff line number Diff line change @@ -7763,14 +7763,19 @@ SourceRange VarDecl::getSourceRange() const {
7763
7763
return getNameLoc ();
7764
7764
}
7765
7765
7766
- SourceRange VarDecl::getTypeSourceRangeForDiagnostics () const {
7766
+ SourceRange AbstractStorageDecl::getTypeSourceRangeForDiagnostics () const {
7767
+ // Subscripts always have an explicitly-written type.
7768
+ if (auto *SD = dyn_cast<SubscriptDecl>(this ))
7769
+ return SD->getElementTypeSourceRange ();
7770
+
7767
7771
// For a parameter, map back to its parameter to get the TypeLoc.
7768
7772
if (auto *PD = dyn_cast<ParamDecl>(this )) {
7769
7773
if (auto typeRepr = PD->getTypeRepr ())
7770
7774
return typeRepr->getSourceRange ();
7771
7775
}
7772
-
7773
- Pattern *Pat = getParentPattern ();
7776
+
7777
+ auto *VD = cast<VarDecl>(this );
7778
+ Pattern *Pat = VD->getParentPattern ();
7774
7779
if (!Pat || Pat->isImplicit ())
7775
7780
return SourceRange ();
7776
7781
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