Fix ICE when interpolating a function call in a template declaration#11056
Open
timotheeguerin wants to merge 1 commit into
Open
Fix ICE when interpolating a function call in a template declaration#11056timotheeguerin wants to merge 1 commit into
timotheeguerin wants to merge 1 commit into
Conversation
…late declaration
A string template interpolating a value-returning function call that
references a template parameter (e.g. `@doc("${fn(T)}")`) crashed with
"Expected type.". The function call returns null (the value-world
equivalent of errorType) in a template declaration; the template now
propagates that null instead of asserting, consistent with
checkArrayValue/checkObjectValue. The value is resolved at instantiation.
Fixes microsoft#11054
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11054
Problem
Compiling a string template that interpolates a function call referencing a template parameter on a template declaration crashed with an internal compiler error:
Root cause
In a template declaration the function call can't be evaluated yet, so
checkFunctionCall→getDefaultFunctionResultreturnsnullfor a value-returning function (the same behavior already used for a direct decorator arg like@doc(fn(T))).nullis the value-world equivalent oferrorType.checkStringTemplateExpresiondidn't handle anullspan: bothhasValue/hasTypestayedfalse, execution fell into the type branch, andcompilerAssert(typeOrValue !== null && !isValue(typeOrValue), "Expected type.")fired.Fix
If any span resolves to
null, the whole string template resolves tonull— propagating the error sentinel up exactly likecheckArrayValue/checkObjectValuedo for value aggregates, rather than fabricating a partial string. The value is re-evaluated against the real argument when the template is instantiated. This also let the now-redundant per-branchnullchecks be removed.Tests
Added regression tests in
string-template.test.ts:Crud<Foo>produces the expected doc value).