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 @@ -5946,6 +5946,13 @@ class AbstractStorageDecl : public ValueDecl {
5946
5946
// / Return the interface type of the stored value.
5947
5947
Type getValueInterfaceType () const ;
5948
5948
5949
+ // / Retrieve the source range of the variable type, or an invalid range if the
5950
+ // / variable's type is not explicitly written in the source.
5951
+ // /
5952
+ // / Only for use in diagnostics. It is not always possible to always
5953
+ // / precisely point to the variable type because of type aliases.
5954
+ SourceRange getTypeSourceRangeForDiagnostics () const ;
5955
+
5949
5956
// / Determine how this storage is implemented.
5950
5957
StorageImplInfo getImplInfo () const ;
5951
5958
@@ -6380,13 +6387,6 @@ class VarDecl : public AbstractStorageDecl {
6380
6387
// / and not just getInterfaceType().
6381
6388
Type getTypeInContext () const ;
6382
6389
6383
- // / Retrieve the source range of the variable type, or an invalid range if the
6384
- // / variable's type is not explicitly written in the source.
6385
- // /
6386
- // / Only for use in diagnostics. It is not always possible to always
6387
- // / precisely point to the variable type because of type aliases.
6388
- SourceRange getTypeSourceRangeForDiagnostics () const ;
6389
-
6390
6390
// / Determine the mutability of this variable declaration when
6391
6391
// / accessed from a given declaration context.
6392
6392
StorageMutability mutability (
Original file line number Diff line number Diff line change @@ -7746,14 +7746,19 @@ SourceRange VarDecl::getSourceRange() const {
7746
7746
return getNameLoc ();
7747
7747
}
7748
7748
7749
- SourceRange VarDecl::getTypeSourceRangeForDiagnostics () const {
7749
+ SourceRange AbstractStorageDecl::getTypeSourceRangeForDiagnostics () const {
7750
+ // Subscripts always have an explicitly-written type.
7751
+ if (auto *SD = dyn_cast<SubscriptDecl>(this ))
7752
+ return SD->getElementTypeSourceRange ();
7753
+
7750
7754
// For a parameter, map back to its parameter to get the TypeLoc.
7751
7755
if (auto *PD = dyn_cast<ParamDecl>(this )) {
7752
7756
if (auto typeRepr = PD->getTypeRepr ())
7753
7757
return typeRepr->getSourceRange ();
7754
7758
}
7755
-
7756
- Pattern *Pat = getParentPattern ();
7759
+
7760
+ auto *VD = cast<VarDecl>(this );
7761
+ Pattern *Pat = VD->getParentPattern ();
7757
7762
if (!Pat || Pat->isImplicit ())
7758
7763
return SourceRange ();
7759
7764
Original file line number Diff line number Diff line change @@ -3705,15 +3705,12 @@ bool AssociatedTypeInference::diagnoseNoSolutions(
3705
3705
failed.Result .getKind () != CheckTypeWitnessResult::Superclass) {
3706
3706
Type resultType;
3707
3707
SourceRange typeRange;
3708
- if (auto *var = dyn_cast<VarDecl >(failed.Witness )) {
3709
- resultType = var ->getValueInterfaceType ();
3710
- typeRange = var ->getTypeSourceRangeForDiagnostics ();
3708
+ if (auto *storage = dyn_cast<AbstractStorageDecl >(failed.Witness )) {
3709
+ resultType = storage ->getValueInterfaceType ();
3710
+ typeRange = storage ->getTypeSourceRangeForDiagnostics ();
3711
3711
} else if (auto *func = dyn_cast<FuncDecl>(failed.Witness )) {
3712
3712
resultType = func->getResultInterfaceType ();
3713
3713
typeRange = func->getResultTypeSourceRange ();
3714
- } else if (auto *subscript = dyn_cast<SubscriptDecl>(failed.Witness )) {
3715
- resultType = subscript->getElementInterfaceType ();
3716
- typeRange = subscript->getElementTypeSourceRange ();
3717
3714
}
3718
3715
3719
3716
// If the type witness was inferred from an existential
You can’t perform that action at this time.
0 commit comments