Commit dfd5150
fix(generator): resolve jagged array syntax errors and centralize array creation logic
Fixed critical bugs in code generation for complex array types (jagged, multi-dimensional,
and mixed arrays) across multiple built-in type generators. The generators were manually
constructing array creation syntax which caused compilation errors for complex array types.
Root cause:
- ArrayGenerator.cs, QueueGenerator.cs, and ArraySegmentGenerator.cs had duplicate logic
for array creation that incorrectly handled complex types like int[][][,] or byte[][,]
- For example: `new byte[][length]` instead of `new byte[length][]`
Solution:
1. Created shared `GetArrayCreationString()` helper method in NinoBuiltInTypeGenerator.cs
that correctly handles all array types by inserting dimension specifier before the
first bracket, accounting for generics
2. Updated ArrayGenerator.cs to use helper for both 1D and multi-dimensional arrays
3. Updated QueueGenerator.cs to use `var` for type inference instead of explicit declaration
4. Updated ArraySegmentGenerator.cs to use the helper method
5. Audited all other generators (Immutable*, LinkedList, PriorityQueue, Stack) - confirmed safe
Testing:
- Added comprehensive tests for Queue/Stack with complex arrays (int[][][,], string[,][][][])
- Added ArraySegment tests with jagged arrays (byte[], int[][], int[][][])
- Added PriorityQueue tests for .NET 6.0+ with:
* Jagged arrays (byte[][], int[][][])
* 2D arrays (int[,])
* 3D arrays (int[,,])
* Mixed jagged/multi-dim (int[][,])
* Mixed multi-dim/jagged (int[,][])
- All 7 test methods (5 original + 2 new) pass across .NET 6.0, 8.0, and netstandard2.1
This eliminates manual array syntax construction across the codebase, preventing future
regressions and ensuring consistent behavior for all complex array types.
Closes #161
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 3b2a575 commit dfd5150
File tree
5 files changed
+460
-65
lines changed- src
- Nino.Generator
- BuiltInType
- Template
- Nino.UnitTests
5 files changed
+460
-65
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | 203 | | |
232 | 204 | | |
233 | 205 | | |
| |||
254 | 226 | | |
255 | 227 | | |
256 | 228 | | |
257 | | - | |
| 229 | + | |
258 | 230 | | |
259 | 231 | | |
260 | 232 | | |
| |||
315 | 287 | | |
316 | 288 | | |
317 | 289 | | |
318 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
319 | 293 | | |
320 | 294 | | |
321 | 295 | | |
| |||
393 | 367 | | |
394 | 368 | | |
395 | 369 | | |
396 | | - | |
| 370 | + | |
397 | 371 | | |
398 | 372 | | |
399 | 373 | | |
| |||
469 | 443 | | |
470 | 444 | | |
471 | 445 | | |
472 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
473 | 449 | | |
474 | 450 | | |
475 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | 150 | | |
157 | 151 | | |
158 | 152 | | |
159 | 153 | | |
160 | 154 | | |
161 | 155 | | |
162 | | - | |
| 156 | + | |
163 | 157 | | |
164 | 158 | | |
165 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | 288 | | |
309 | 289 | | |
310 | 290 | | |
311 | 291 | | |
312 | | - | |
| 292 | + | |
313 | 293 | | |
314 | 294 | | |
315 | 295 | | |
| |||
321 | 301 | | |
322 | 302 | | |
323 | 303 | | |
324 | | - | |
| 304 | + | |
325 | 305 | | |
326 | 306 | | |
327 | 307 | | |
| |||
462 | 442 | | |
463 | 443 | | |
464 | 444 | | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | 445 | | |
469 | 446 | | |
470 | 447 | | |
| |||
477 | 454 | | |
478 | 455 | | |
479 | 456 | | |
480 | | - | |
| 457 | + | |
481 | 458 | | |
482 | 459 | | |
483 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
214 | 254 | | |
215 | 255 | | |
216 | 256 | | |
| |||
0 commit comments