@@ -18,13 +18,20 @@ public static Expression CreatePattern(this Context cx, PatternSyntax syntax, IE
1818 case DeclarationPatternSyntax declPattern :
1919 // Creates a single local variable declaration.
2020 {
21- if ( declPattern . Designation is VariableDesignationSyntax designation && cx . Model ( syntax ) . GetDeclaredSymbol ( designation ) is ILocalSymbol symbol )
21+ if ( declPattern . Designation is VariableDesignationSyntax designation )
2222 {
23- var type = Type . Create ( cx , symbol . Type ) ;
24-
25- return VariableDeclaration . Create ( cx , symbol , type , cx . Create ( syntax . GetLocation ( ) ) , cx . Create ( designation . GetLocation ( ) ) , false , parent , child ) ;
23+ if ( cx . Model ( syntax ) . GetDeclaredSymbol ( designation ) is ILocalSymbol symbol )
24+ {
25+ var type = Type . Create ( cx , symbol . Type ) ;
26+ return VariableDeclaration . Create ( cx , symbol , type , declPattern . Type , cx . Create ( syntax . GetLocation ( ) ) , cx . Create ( designation . GetLocation ( ) ) , false , parent , child ) ;
27+ }
28+ if ( designation is DiscardDesignationSyntax )
29+ {
30+ return Expressions . TypeAccess . Create ( cx , declPattern . Type , parent , child ) ;
31+ }
32+ throw new InternalError ( designation , "Designation pattern not handled" ) ;
2633 }
27- throw new InternalError ( syntax , "Is pattern not handled" ) ;
34+ throw new InternalError ( declPattern , "Declaration pattern not handled" ) ;
2835 }
2936
3037 case RecursivePatternSyntax recPattern :
@@ -40,7 +47,7 @@ public static Expression CreatePattern(this Context cx, PatternSyntax syntax, IE
4047 {
4148 var type = Type . Create ( cx , symbol . Type ) ;
4249
43- return VariableDeclaration . Create ( cx , symbol , type , cx . Create ( syntax . GetLocation ( ) ) , cx . Create ( varDesignation . GetLocation ( ) ) , false , parent , child ) ;
50+ return VariableDeclaration . Create ( cx , symbol , type , null , cx . Create ( syntax . GetLocation ( ) ) , cx . Create ( varDesignation . GetLocation ( ) ) , false , parent , child ) ;
4451 }
4552 else
4653 {
@@ -54,7 +61,7 @@ public static Expression CreatePattern(this Context cx, PatternSyntax syntax, IE
5461 return new Discard ( cx , dp , parent , child ) ;
5562
5663 default :
57- throw new InternalError ( syntax , "Is pattern not handled" ) ;
64+ throw new InternalError ( syntax , "Pattern not handled" ) ;
5865 }
5966 }
6067 }
@@ -108,7 +115,7 @@ public RecursivePattern(Context cx, RecursivePatternSyntax syntax, IExpressionPa
108115 {
109116 var type = Type . Create ( cx , symbol . Type ) ;
110117
111- VariableDeclaration . Create ( cx , symbol , type , cx . Create ( syntax . GetLocation ( ) ) , cx . Create ( designation . GetLocation ( ) ) , false , this , 0 ) ;
118+ VariableDeclaration . Create ( cx , symbol , type , null , cx . Create ( syntax . GetLocation ( ) ) , cx . Create ( designation . GetLocation ( ) ) , false , this , 0 ) ;
112119 }
113120
114121 if ( syntax . PositionalPatternClause is PositionalPatternClauseSyntax posPc )
@@ -131,19 +138,14 @@ private IsPattern(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.IS))
131138
132139 private void PopulatePattern ( PatternSyntax pattern , TypeSyntax optionalType , SyntaxToken varKeyword , VariableDesignationSyntax designation )
133140 {
134- bool isVar = optionalType is null ;
135- if ( ! isVar )
136- Expressions . TypeAccess . Create ( cx , optionalType , this , 1 ) ;
137-
141+ var isVar = optionalType is null ;
138142 if ( ! ( designation is null ) && cx . Model ( pattern ) . GetDeclaredSymbol ( designation ) is ILocalSymbol symbol )
139143 {
140144 var type = Type . Create ( cx , symbol . Type ) ;
141-
142- if ( isVar )
143- new Expression ( new ExpressionInfo ( cx , type , cx . Create ( varKeyword . GetLocation ( ) ) , ExprKind . TYPE_ACCESS , this , 1 , false , null ) ) ;
144-
145- VariableDeclaration . Create ( cx , symbol , type , cx . Create ( pattern . GetLocation ( ) ) , cx . Create ( designation . GetLocation ( ) ) , isVar , this , 2 ) ;
145+ VariableDeclaration . Create ( cx , symbol , type , optionalType , cx . Create ( pattern . GetLocation ( ) ) , cx . Create ( designation . GetLocation ( ) ) , isVar , this , 1 ) ;
146146 }
147+ else if ( ! isVar )
148+ Expressions . TypeAccess . Create ( cx , optionalType , this , 1 ) ;
147149 }
148150
149151 protected override void Populate ( )
@@ -152,7 +154,7 @@ protected override void Populate()
152154 switch ( Syntax . Pattern )
153155 {
154156 case ConstantPatternSyntax constantPattern :
155- Create ( cx , constantPattern . Expression , this , 3 ) ;
157+ Create ( cx , constantPattern . Expression , this , 1 ) ;
156158 return ;
157159 case VarPatternSyntax varPattern :
158160 PopulatePattern ( varPattern , null , varPattern . VarKeyword , varPattern . Designation ) ;
@@ -161,7 +163,7 @@ protected override void Populate()
161163 PopulatePattern ( declPattern , declPattern . Type , default ( SyntaxToken ) , declPattern . Designation ) ;
162164 return ;
163165 case RecursivePatternSyntax recPattern :
164- new RecursivePattern ( cx , recPattern , this , 3 ) ;
166+ new RecursivePattern ( cx , recPattern , this , 1 ) ;
165167 return ;
166168 default :
167169 throw new InternalError ( Syntax , "Is pattern not handled" ) ;
0 commit comments