@@ -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 )
@@ -135,7 +142,7 @@ private void PopulatePattern(PatternSyntax pattern, TypeSyntax optionalType, Syn
135142 if ( ! ( designation is null ) && cx . Model ( pattern ) . GetDeclaredSymbol ( designation ) is ILocalSymbol symbol )
136143 {
137144 var type = Type . Create ( cx , symbol . Type ) ;
138- 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 ) ;
139146 }
140147 else if ( ! isVar )
141148 Expressions . TypeAccess . Create ( cx , optionalType , this , 1 ) ;
0 commit comments