Skip to content

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

Merged
merged 2 commits into from
Jun 11, 2021
Merged

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Jun 11, 2021

Fixes #32592 and fixes #32193 and probably also fixes #32237.

The way the TypeParamDirective was instantiated before ran the risk of having an undefined Directive 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.

@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jun 11, 2021
@captainsafia captainsafia added area-razor.compiler and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Jun 11, 2021
@captainsafia captainsafia marked this pull request as ready for review June 11, 2021 15:50
@captainsafia captainsafia requested a review from Pilchie as a code owner June 11, 2021 15:50
@captainsafia captainsafia requested review from javiercn, pranavkm and NTaylorMullen and removed request for Pilchie June 11, 2021 15:50
Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Looks great!

@@ -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;
Copy link
Contributor

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?

Copy link
Member Author

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.

@captainsafia captainsafia merged commit 3450895 into main Jun 11, 2021
@captainsafia captainsafia deleted the safia/32592 branch June 11, 2021 17:37
@ghost ghost added this to the 6.0-preview6 milestone Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants