Skip to content

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

@pkozlowski-opensource

Description

@pkozlowski-opensource

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions