Skip to content

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

Closed

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

Activity

  1. self-assigned this
    on Jul 4, 2024
  2. added
    area: compiler
    on Jul 4, 2024
  3. added this to the needsTriage milestone on Jul 4, 2024
  4. added a commit that references this issue on Jul 4, 2024
    3947cf2
  5. added a commit that references this issue on Jul 5, 2024
    cdebf75
  6. added a commit that references this issue on Jul 5, 2024
    d7ab5c3
  7. angular-automatic-lock-bot commented on Aug 5, 2024

    @angular-automatic-lock-bot

    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.

  8. locked and limited conversation to collaborators on Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilerstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions