Skip to content

@let variable used in @if condition but declared after the block doesn't throw NG8016 #56842

@cexbrayat

Description

@cexbrayat

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

compiler-cli

Is this a regression?

No

Description

The compiler does allow to use a @let variable inside a block, even if it declared after the block.

For example, this work:

@if (true) {
  <h1>Hello from {{ aliasName }}!</h1>
}
@let aliasName = name;    

But it should throw if the variable is used inside the condition of the block:

@if (aliasName) {
  <h1>Hello from {{ aliasName }}!</h1>
}
@let aliasName = name;    

It currently doesn't throw the NG8016 error, whereas it should as this code doesn't work.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-3uvfdi?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=package.json,src%2Fmain.ts&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)

ngular CLI: 18.1.0-rc.1
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 18.1.0-rc.0
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1801.0-rc.1
@angular-devkit/build-angular   18.1.0-rc.1
@angular-devkit/core            18.1.0-rc.1
@angular-devkit/schematics      18.1.0-rc.1
@angular/cli                    18.1.0-rc.1
@schematics/angular             18.1.0-rc.1
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.7

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions