Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: cryptic error when the track expression is empty for the control flow @for #54763

Closed
pkozlowski-opensource opened this issue Mar 8, 2024 · 1 comment
Assignees
Labels
area: compiler Issues related to `ngc`, Angular's template compiler bug core: control flow Issues related to the built-in control flow (@if, @for, @switch) hotlist: error messages state: has PR
Milestone

Comments

@pkozlowski-opensource
Copy link
Member

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

Writing the following in a template: @for (item of items; track ) will result in the cryptic compilation error:

✘ [ERROR] Angular compilation emit failed. [plugin angular-compiler]

  Error: AssertionError: Unsupported reification of ir.Expression kind: EmptyExpr
      at reifyIrExpression (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:22452:19)
      at transformExpressionsInExpression (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:10647:12)
      at transformExpressionsInOp (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:10489:24)
      at reifyCreateOperations (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:22136:9)
      at Object.reify [as fn] (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:22105:9)
      at transform (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:24249:19)
      at compileComponentFromMetadata (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler/fesm2022/compiler.mjs:30764:9)
      at ComponentDecoratorHandler.compileFull (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler-cli/bundles/chunk-WYZJV3LZ.js:7628:17)
      at TraitCompiler.compile (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler-cli/bundles/chunk-WYZJV3LZ.js:2618:38)
      at IvyCompilationVisitor.visitClassDeclaration (file:///Users/pkozlowski/trash/ng-track-by/node_modules/@angular/compiler-cli/bundles/chunk-WYZJV3LZ.js:2958:37)

For 17.2 and the previous template compilation pipeline we got a different, but equally cryptic error:

  TypeError: Cannot read properties of undefined (reading 'visit')
      at convertPureComponentScopeFunction (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:7370:33)
      at TemplateDefinitionBuilder.createTrackByFunction (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:29677:23)
      at TemplateDefinitionBuilder.visitForLoopBlock (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:29546:109)
      at ForLoopBlock.visit (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:4281:24)
      at visitAll$1 (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:4467:34)
      at TemplateDefinitionBuilder.buildTemplateFunction (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:28541:9)
      at Module.compileComponentFromMetadata (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler/fesm2022/compiler.mjs:30970:60)
      at ComponentDecoratorHandler.compileFull (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler-cli/bundles/chunk-LVVK56VK.js:7660:35)
      at TraitCompiler.compile (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler-cli/bundles/chunk-LVVK56VK.js:2673:38)
      at IvyCompilationVisitor.visitClassDeclaration (file:///home/projects/stackblitz-starters-vlsqkz/node_modules/@angular/compiler-cli/bundles/chunk-LVVK56VK.js:3013:37)

Instead, we should detect those situations earlier and report the same / similar error as missing track keyword.

Interestingly the same applies to the language service where the described situation is not reported.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-vlsqkz?description=An%20angular-cli%20project%20based%20on%20@angular/animations,%20@angular/common,%20@angular/compiler,%20@angular/core,%20@angular/forms,%20@angular/platform-browser,%20@angular/platform-browser-dynamic,%20@angular/router,%20core-js,%20rxjs,%20tslib%20and%20zone.js&file=src%2Fmain.ts,package.json&template=node&title=Angular%20Starter

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

@pkozlowski-opensource pkozlowski-opensource added hotlist: error messages area: compiler Issues related to `ngc`, Angular's template compiler bug core: control flow Issues related to the built-in control flow (@if, @for, @switch) labels Mar 8, 2024
@ngbot ngbot bot added this to the needsTriage milestone Mar 8, 2024
@crisbeto crisbeto self-assigned this Mar 8, 2024
crisbeto added a commit to crisbeto/angular that referenced this issue Mar 8, 2024
Fixes that the template parser wasn't catching empty expressions in the `track` parameter of for loops.

Fixes angular#54763.
atscott pushed a commit that referenced this issue Mar 11, 2024
Fixes that the template parser wasn't catching empty expressions in the `track` parameter of for loops.

Fixes #54763.

PR Close #54772
atscott pushed a commit that referenced this issue Mar 11, 2024
Fixes that the template parser wasn't catching empty expressions in the `track` parameter of for loops.

Fixes #54763.

PR Close #54772
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler bug core: control flow Issues related to the built-in control flow (@if, @for, @switch) hotlist: error messages state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants