Skip to content

fix(compiler): template type checking not reporting diagnostics for incompatible type comparisons#52322

Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:52315/switch-incompatible-types
Closed

fix(compiler): template type checking not reporting diagnostics for incompatible type comparisons#52322
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:52315/switch-incompatible-types

Conversation

@crisbeto
Copy link
Member

In #52110 the compiler was changed to produce if statements when type checking @switch in order to avoid a bug in the TypeScript compiler. In order to avoid duplicate diagnostics, the main @switch expression was ignored in each of the @case comparisons. This appears to have caused a regression where comparing incompatible types wasn't being reported anymore.

These changes resolve the issue by wrapping the expression in parentheses which allows the compiler to report comparison diagnostics while ignoring diagnostics in the expression itself.

Fixes #52315.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler target: rc This PR is targeted for the next release-candidate labels Oct 23, 2023
@crisbeto crisbeto added this to the v17-final milestone Oct 23, 2023
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this diagnostic isn't the best, but it's a side-effect of us having to use if instead of switch to represent the expression. We can't do much about it for now, but it'll be fixed automatically once we go back to using switch statements in the TCB.

…ncompatible type comparisons

In angular#52110 the compiler was changed to produce `if` statements when type checking `@switch` in order to avoid a bug in the TypeScript compiler. In order to avoid duplicate diagnostics, the main `@switch` expression was ignored in each of the `@case` comparisons. This appears to have caused a regression where comparing incompatible types wasn't being reported anymore.

These changes resolve the issue by wrapping the expression in parentheses which allows the compiler to report comparison diagnostics while ignoring diagnostics in the expression itself.

Fixes angular#52315.
@crisbeto crisbeto force-pushed the 52315/switch-incompatible-types branch from 6bd2ee8 to 5f453db Compare October 23, 2023 07:49
@crisbeto crisbeto requested a review from atscott October 23, 2023 08:13
@crisbeto crisbeto marked this pull request as ready for review October 23, 2023 08:13
@crisbeto crisbeto removed the request for review from atscott October 23, 2023 15:43
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 23, 2023
@dylhunn
Copy link
Contributor

dylhunn commented Oct 23, 2023

This PR was merged into the repository by commit dc3f7cb.

@dylhunn dylhunn closed this in dc3f7cb Oct 23, 2023
dylhunn pushed a commit that referenced this pull request Oct 23, 2023
…ncompatible type comparisons (#52322)

In #52110 the compiler was changed to produce `if` statements when type checking `@switch` in order to avoid a bug in the TypeScript compiler. In order to avoid duplicate diagnostics, the main `@switch` expression was ignored in each of the `@case` comparisons. This appears to have caused a regression where comparing incompatible types wasn't being reported anymore.

These changes resolve the issue by wrapping the expression in parentheses which allows the compiler to report comparison diagnostics while ignoring diagnostics in the expression itself.

Fixes #52315.

PR Close #52322
@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 Nov 23, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…ncompatible type comparisons (angular#52322)

In angular#52110 the compiler was changed to produce `if` statements when type checking `@switch` in order to avoid a bug in the TypeScript compiler. In order to avoid duplicate diagnostics, the main `@switch` expression was ignored in each of the `@case` comparisons. This appears to have caused a regression where comparing incompatible types wasn't being reported anymore.

These changes resolve the issue by wrapping the expression in parentheses which allows the compiler to report comparison diagnostics while ignoring diagnostics in the expression itself.

Fixes angular#52315.

PR Close angular#52322
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@switch does not have type awareness in case statements

3 participants