Skip to content
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

Specially handle some scenarios for type parameters with 'allows ref struct' constraint #73025

Merged

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs AlekseyTs requested review from jjonescz and cston April 15, 2024 17:16
@AlekseyTs AlekseyTs requested a review from a team as a code owner April 15, 2024 17:16
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 15, 2024
@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler Please review

@@ -527,9 +527,14 @@ public static bool IsPossibleArrayGenericInterface(this TypeSymbol type)
return false;
}

internal static bool IsErrorTypeOrRefLikeType(this TypeSymbol type)
internal static bool IsErrorTypeOrIsRefLikeTypeOrAllowByRefLike(this TypeSymbol type)
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Suggested change
internal static bool IsErrorTypeOrIsRefLikeTypeOrAllowByRefLike(this TypeSymbol type)
internal static bool IsErrorTypeOrIsRefLikeTypeOrAllowsByRefLike(this TypeSymbol type)
``` #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to do this rename in the next PR.

var src2 = @"
public class Helper
{
public static void Test1<T>(scoped T x)
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Consider testing scoped ref T parameter as well. #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider testing scoped ref T parameter as well.

Why do you think this is interesting? Any ref parameter can be declared scoped, no type restrictions for that.

}

[Fact]
public void ScopedTypeParameter_02()
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Nit: looks like this is testing locals, not parameters. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nit: looks like this is testing locals, not parameters.

The name of the test says "TypeParameter" and that is what the test is testing.


public class Helper
{
static void Test1<T>([UnscopedRef] params scoped T x)
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Consider testing similar scenario without params #Resolved

}

[Fact]
public void AutoProperty()
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Consider testing similar scenario with synthesized record properties #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider testing similar scenario with synthesized record properties

RestrictedTypesInRecords will be added in the next PR

var src = @"
abstract class Base
{
protected abstract T Test1<T>(scoped T x)
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Should we test similar scenario with params T which is implicitly scoped? #Resolved

@@ -333,7 +333,7 @@ private enum IsParamsValues : byte
Debug.Assert(refKind != RefKind.None);
scope = ScopedKind.ScopedRef;
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Can we have T: allows ref struct parameter symbol which is also byref, in metadata? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we have T: allows ref struct parameter symbol which is also byref, in metadata?

We can have one in source as well. There is nothing wrong with that.

{
// ref struct R2<T> where T : allows ref struct
// {
// public ref T F;
Copy link
Member

@jjonescz jjonescz Apr 16, 2024

Choose a reason for hiding this comment

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

Consider adding a test like this for a parameter as well. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider adding a test like this for a parameter as well.

Parameters like that are supported and there is already a bunch of tests covering them.

@AlekseyTs
Copy link
Contributor Author

@jjonescz Thank you for the test suggestions. However, I am going through specific code paths (marked with PROTOTYPE comments, quate possibly some are marked in the first commit of this PR), adjusting the code paths (if necessary) and adding targeted tests for those specific code paths. I will capture you suggestions as PROTOTYPE comments in the next PR, but I will not be adding the tests at the moment.

@AlekseyTs AlekseyTs requested a review from jjonescz April 16, 2024 12:53
@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review

// public static S P4 {get; set;}
Diagnostic(ErrorCode.ERR_FieldAutoPropCantBeByRefLike, "S").WithArguments("S").WithLocation(13, 19)
);
}
Copy link
Member

@cston cston Apr 16, 2024

Choose a reason for hiding this comment

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

}

Consider testing capturing primary constructor parameter of type allows ref struct. #Resolved

// protected abstract override void Test2(S y, out S z);
Diagnostic(ErrorCode.ERR_ScopedMismatchInParameterOfOverrideOrImplementation, "Test2").WithArguments("y").WithLocation(14, 38)
);
}
Copy link
Member

@cston cston Apr 16, 2024

Choose a reason for hiding this comment

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

}

Consider testing ERR_ScopedMismatchInParameterOfPartial and ERR_ScopedMismatchInParameterOfTarget. #Resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - RefStructInterfaces untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants