From e033f3b423c1bb454f9ac61d9d51327cda671099 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sun, 21 Nov 2021 00:12:51 -0800 Subject: [PATCH 01/11] Add HasValidate --- .../CSharp/Portable/Binder/Binder_Patterns.cs | 2 -- .../Binder/DecisionDagBuilder_ListPatterns.cs | 2 -- .../Portable/BoundTree/BoundDagEvaluation.cs | 8 ++++++++ ...rAccess.cs => BoundImplicitIndexerAccess.cs} | 6 ++++++ .../Portable/BoundTree/BoundListPattern.cs | 17 +++++++++++++++++ .../CSharp/Portable/BoundTree/BoundNodes.xml | 10 +++++----- .../CSharp/Portable/BoundTree/BoundNodes.xsd | 1 + .../Portable/BoundTree/BoundSlicePattern.cs | 16 ++++++++++++++++ .../Generated/BoundNodes.xml.Generated.cs | 15 +++++++++++++++ .../BoundTreeGenerator/BoundNodeClassWriter.cs | 15 +++++++++++++++ 10 files changed, 83 insertions(+), 9 deletions(-) rename src/Compilers/CSharp/Portable/BoundTree/{BoundIndexOrRangePatternIndexerAccess.cs => BoundImplicitIndexerAccess.cs} (84%) create mode 100644 src/Compilers/CSharp/Portable/BoundTree/BoundListPattern.cs create mode 100644 src/Compilers/CSharp/Portable/BoundTree/BoundSlicePattern.cs diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs index 10ef681c61de6..bf19f78e71699 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs @@ -238,7 +238,6 @@ private BoundPattern BindSlicePattern( pattern = BindPattern(node.Pattern, sliceType, GetValEscape(sliceType, inputValEscape), permitDesignations, hasErrors, diagnostics); } - Debug.Assert(GetIndexerOrImplicitIndexerSymbol(indexerAccess) is var _); return new BoundSlicePattern(node, pattern, indexerAccess, receiverPlaceholder, argumentPlaceholder, inputType: inputType, narrowedType: inputType, hasErrors); } @@ -317,7 +316,6 @@ private BoundListPattern BindListPattern( inputValEscape, permitDesignations, typeSyntax: null, diagnostics, ref hasErrors, out Symbol? variableSymbol, out BoundExpression? variableAccess); - Debug.Assert(GetIndexerOrImplicitIndexerSymbol(indexerAccess) is var _); return new BoundListPattern( syntax: node, subpatterns: subpatterns, hasSlice: sawSlice, lengthAccess: lengthAccess, indexerAccess: indexerAccess, receiverPlaceholder, argumentPlaceholder, variable: variableSymbol, diff --git a/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder_ListPatterns.cs b/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder_ListPatterns.cs index 9654b37e324db..1a23e72c651d4 100644 --- a/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder_ListPatterns.cs +++ b/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder_ListPatterns.cs @@ -60,7 +60,6 @@ private Tests MakeTestsAndBindingsForListPattern(BoundDagTemp input, BoundListPa Debug.Assert(slice.ReceiverPlaceholder is not null); Debug.Assert(slice.ArgumentPlaceholder is not null); - Debug.Assert(slice.IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess); var sliceEvaluation = new BoundDagSliceEvaluation(slicePattern.Syntax, slicePattern.InputType, lengthTemp, startIndex: startIndex, endIndex: index, slice.IndexerAccess, slice.ReceiverPlaceholder, slice.ArgumentPlaceholder, input); @@ -76,7 +75,6 @@ private Tests MakeTestsAndBindingsForListPattern(BoundDagTemp input, BoundListPa Debug.Assert(list.ReceiverPlaceholder is not null); Debug.Assert(list.ArgumentPlaceholder is not null); - Debug.Assert(list.IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess); var indexEvaluation = new BoundDagIndexerEvaluation(subpattern.Syntax, subpattern.InputType, lengthTemp, index++, list.IndexerAccess, list.ReceiverPlaceholder, list.ArgumentPlaceholder, input); diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundDagEvaluation.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundDagEvaluation.cs index a20ecdb9d9722..5a85b268fc965 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundDagEvaluation.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundDagEvaluation.cs @@ -108,6 +108,10 @@ public override bool IsEquivalentTo(BoundDagEvaluation obj) return base.IsEquivalentTo(obj) && this.Index == ((BoundDagIndexerEvaluation)obj).Index; } + private partial void Validate() + { + Debug.Assert(IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess); + } } partial class BoundDagSliceEvaluation @@ -119,6 +123,10 @@ public override bool IsEquivalentTo(BoundDagEvaluation obj) (BoundDagSliceEvaluation)obj is var e && this.StartIndex == e.StartIndex && this.EndIndex == e.EndIndex; } + private partial void Validate() + { + Debug.Assert(IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess); + } } partial class BoundDagAssignmentEvaluation diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundIndexOrRangePatternIndexerAccess.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundImplicitIndexerAccess.cs similarity index 84% rename from src/Compilers/CSharp/Portable/BoundTree/BoundIndexOrRangePatternIndexerAccess.cs rename to src/Compilers/CSharp/Portable/BoundTree/BoundImplicitIndexerAccess.cs index 8c962909e29af..667c866515993 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundIndexOrRangePatternIndexerAccess.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundImplicitIndexerAccess.cs @@ -29,5 +29,11 @@ internal BoundExpression GetReceiver() Debug.Assert(receiver is not null); return receiver; } + + private partial void Validate() + { + Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal); + Debug.Assert(IndexerOrSliceAccess is BoundIndexerAccess or BoundCall); + } } } diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundListPattern.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundListPattern.cs new file mode 100644 index 0000000000000..94dc5559b57b1 --- /dev/null +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundListPattern.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; + +namespace Microsoft.CodeAnalysis.CSharp +{ + internal partial class BoundListPattern + { + private partial void Validate() + { + Debug.Assert(LengthAccess is BoundPropertyAccess or BoundBadExpression); + Debug.Assert(Binder.GetIndexerOrImplicitIndexerSymbol(IndexerAccess) is var _); + } + } +} diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml index 3fa57b3b32270..bcba580fb3f5b 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml @@ -1519,7 +1519,7 @@ - + @@ -1539,7 +1539,7 @@ - + @@ -2066,7 +2066,7 @@ - + @@ -2242,7 +2242,7 @@ - + @@ -2260,7 +2260,7 @@ - +