Repository navigation
fix(compiler): Expression converter typo - #37361
ajitsinghkaler wants to merge 1 commit into
Conversation
In expression converter for literal values of null, undefined, true, or false type interference was to be done but it was not done for value false. Added false also to the check. Fixes angular#21233
|
We definitively need an additional test (one that would fail without the code change and starts passing with the code change) |
|
@pkozlowski-opensource I don't see any unit tests added for the method visitLiteralPrimitive() do I write an integration test |
|
Ideally there should be a test of some kind to demonstrate this. |
AndrewKushnir
left a comment
There was a problem hiding this comment.
@ajitsinghkaler, thanks for creating this PR. As Pawel and Pete mentioned, it'd be great to have a test to verify this change. The code was originally introduced in
82bcd83 and there are some tests there, so may be you can use one of them as a base for the new test.
I'm also adding @alxhub as a reviewer as he may have additional context on this.
Thank you.
|
@AndrewKushnir I tried to write the test but could not understand how to write a test for this can you please help me. |
|
Hi @ajitsinghkaler, I tried to reuse one of the tests from 82bcd83 and was able to trigger the codepath updated in this PR, but I was unable to come up with a case when a test would fail with current state of the master branch and will pass after the change in this PR (which is needed to validate that everything works as needed). May be @petebacondarwin or @alxhub have additional thoughts/ideas. Thank you. |
|
I think the reason we can't make a failing test is that our typing checks tend not to distinguish between See |
|
@petebacondarwin but the type would be <button [id]="computeId(false)"></button>export class MyCmp {
doSomething(param: number): string { return ''; }
}One would expect this not to typecheck, als literal Note that since Ivy, any type information on the output AST is not used at all. |
|
I created a template that looks like this: where The rendered type check block is: I believe that because |
|
I'll have a play with a function call as in your suggestion @JoostK . |
|
So a template like: <button [id]="computeId(false)"></button>doesn't trigger the |
|
After looking into it some more, I can't think of a way to reproduce a bug here. The type is only relevant if a temporary has to be introduced, which only happens for the LHS of safe navigation operators. Therefore, the literal itself is never assigned into a temporary. In the TS emitter, the type is only used when the literal is angular/packages/compiler/src/output/ts_emitter.ts Lines 96 to 103 in f150a30 For the boolean case, the literal will be emitted as is. Therefore, the literal type is retained. Alas, I don't think the code with the bug has a real purpose. |
|
@JoostK so should we remove this code |
|
I think that despite no test (and possibly despite this code being used!!) we should land this change since clearly the current code is not correct. |
|
Closing this since it's been several months- feel free to open a new PR that either cleans up the unnecessary code or adds tests for a behavior change. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In expression converter for literal values of null, undefined, true, or false type interference was to be done but it was not done for value false. Added false also to the check.
Fixes #21233
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
a typo
Issue Number: #21233
What is the new behavior?
typo removed
Does this PR introduce a breaking change?
Other information