Skip to content

Compile error related to nullish coalescing in template  #45413

Closed

Description

@elnipa

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

compiler

Is this a regression?

Yes

Description

After updating one of my projects from v13.1.x to v.13.2.x or v13.3.x the project would not compile anymore with a very generic error message.
Narrowing down the bug was thus very difficult. By successive testing of all modules in the project I was able to achieve a minimal reproduction of the bug.

The following setup crashes the app:

  • nullish coalescing in template which might not be needed (The left side of this nullish coalescing operation does not include 'null' or 'undefined' in its type, therefore the '??' operator can be safely removed.)
  • strictTemplates mode in angular compiler options enabled
  • component using a generic extending a Record

Removing the unnecessary nullish coalescing in this case makes the project compile again.

Please provide a link to a minimal reproduction of the bug

https://github.com/elnipa/ng13.3-null-span-bug

Please provide the exception or error you saw

<e> [webpack-dev-middleware] Error: Cannot read properties of null (reading 'span')
<e>     at analyzingFileEmitter (C:\.....\node_modules\@ngtools\webpack\src\ivy\plugin.js:456:23)
<e>     at processTicksAndRejections (node:internal/process/task_queues:96:5)
<e>     at async AngularWebpackPlugin.rebuildRequiredFiles (C:\.....\node_modules\@ngtools\webpack\src\ivy\plugin.js:281:36)
<e>     at async C:\.....\node_modules\@ngtools\webpack\src\ivy\plugin.js:222:17

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

Angular CLI: 13.3.0
Node: 16.13.0
Package Manager: npm 8.1.0
OS: win32 x64

Angular: 13.3.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.0
@angular-devkit/build-angular   13.3.0
@angular-devkit/core            13.3.0
@angular-devkit/schematics      13.3.0
@schematics/angular             13.3.0
rxjs                            7.5.5
typescript                      4.6.2

Anything else?

No response

Activity

  1. JoostK commented on Mar 22, 2022

    @JoostK
    Member

    There seem to be at least two issues here: Here's what I found out:

    1. the compiler doesn't deal correctly with template source locations when an inline TCB is used.
    2. the usage of null-coalescing here should be valid, as the LHS is nullable. Oh, I missed the ngIf!

    The easiest workaround would be to disable the extended check for nullish coalescing.

  2. added
    area: compiler
    P3
    on Mar 22, 2022
  3. modified the milestone: Backlog on Mar 22, 2022
  4. self-assigned this
    on Mar 26, 2022
  5. added a commit that references this issue on Mar 29, 2022
    14b32fe
  6. added a commit that references this issue on Mar 30, 2022
    aa138d1
  7. added a commit that references this issue on Mar 30, 2022
    7f53c0f
  8. angular-automatic-lock-bot commented on Apr 29, 2022

    @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.

  9. locked and limited conversation to collaborators on Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: compilercompiler: template type-checkingstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions