Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Aug 8, 2022

Adds some tests with basic usage of ref fields to ensure the linker doesn't crash or produce incorrect warnings. Ref structs can't be used as type parameters, so some things like IEnumerable can't be tested.

Please let me know if I'm missing other cases where this could cause some issues.

delegate ref RS2 RefRSParamRefRs2Return (ref RS rs);
delegate ref int RsParamRefIntReturn (RS rs);

public static void Main (string[] args)
Copy link
Member

Choose a reason for hiding this comment

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

I actually don't know if some of these are valid, but still:

  • ref struct in a generic parameter
  • ref return and parameter on a virtual method?
  • Put annotations (DAM/RUC on type) on the ref field - don't care if it works correctly, but should not crash

Copy link
Member Author

@jtschuster jtschuster Aug 8, 2022

Choose a reason for hiding this comment

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

ref struct in a generic parameter

Ref structs will generate CS0306 if used as a type parameter.

ref return and parameter on a virtual method?

Added IRS interface and Base and Derived classes with virtual methods with ref structs as return, ref return, parameter, and ref parameter.

Put annotations (DAM/RUC on type) on the ref field

RUC can't be placed on structs and ref structs can't implement interfaces, so I don't think there's a way that they could be annotated with DAM. I've added DAM on a field and DAM and RUC on a method return and parameter.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot!

- Add virtual methods with ref structs
- Add fields with DAM
- Add method with ref structs with RUC and DAM
Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

Thanks!

using Mono.Linker.Tests.Cases.Expectations.Helpers;

namespace Mono.Linker.Tests.Cases.Basic
{
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Add a comment describing what the test is trying to validate - mainly that it's only meant to validate that linker doesn't crash or do other weird things on ref fields. And that it's not meant as full validation of all functionality around ref fields.

@jtschuster jtschuster merged commit d9aebf3 into dotnet:main Aug 9, 2022
@jtschuster jtschuster deleted the refFieldBasic branch August 9, 2022 19:28
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…r#2952)

Adds test to use ref fields in various ways to confirm that they don't cause the linker to crash.

Commit migrated from dotnet/linker@d9aebf3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants