-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Ensure @typeparam directive descriptor is always set #33456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
...Microsoft.AspNetCore.Razor.Language/src/Components/ComponentConstrainedTypeParamDirective.cs
Show resolved
Hide resolved
@@ -100,7 +100,12 @@ protected override CodeTarget CreateTarget(RazorCodeDocument codeDocument, Razor | |||
{ | |||
@class.BaseType = ComponentsApi.ComponentBase.FullTypeName; | |||
|
|||
var typeParamReferences = documentNode.FindDirectiveReferences(ComponentTypeParamDirective.Directive); | |||
// Constrained type parameters are only supported in Razor language versions v6.0 | |||
var razorLanguageVersion = codeDocument.GetParserOptions()?.Version ?? RazorLanguageVersion.Latest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we want to assume lowest version instead of highest if there isn't one specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, the only scenario where it is undefined is in some test cases for this pass that don't fully configure the ComponentDocumentClassifierPass
with parser options. For that scenario, I figured it made sense to update to the latest.
Assuming this happens to a user, I think it also makes sense to default to the latest since the constrained type param directive can still support unconstrained scenarios.
Fixes #32592 and fixes #32193 and probably also fixes #32237.
The way the
TypeParamDirective
was instantiated before ran the risk of having an undefinedDirective
property if multiple project engines are instantiated. This is more likely to happen in tests that run in parallel and in our compilation flow.I've cleaned this up so that the correct
TypeParamDirective
construct is produced depending on the language version.