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

CS8987 is reported when using lang version < 11 and net7.0 target on scoped mismatch #67638

Closed
jsteinich opened this issue Apr 4, 2023 · 2 comments
Assignees
Milestone

Comments

@jsteinich
Copy link

jsteinich commented Apr 4, 2023

Version Used:

<TargetFramework>net7.0</TargetFramework>
<LangVersion>9</LangVersion>

Steps to Reproduce:

  1. Create an interface in a library which contains a scoped ref parameter
  2. Compile the library using net7.0
  3. Reference the library in a different project that targets net7.0, but uses language version 9
  4. Create a class that implements the interface (it won't have the scoped keyword since not available)
  5. Observe the compile error

Example interface method:

void Deserialize<TInput>(ref Reader<TInput> reader, scoped ref T value);

Example implementation method:

public void Deserialize<TReaderInput>(ref Reader<TReaderInput> reader, ref MyType value)

Diagnostic Id:

CS8987

Expected Behavior:
A CS9074 warning is generated instead. This matches the behavior if the library and project are instead targeting netstandard2.1 (same language versions).

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/low-level-struct-improvements implies that the warning vs error is based on C# version only. (The diagnostic is reported as an error if the mismatched signatures are both using C#11 ref safety rules; otherwise, the diagnostic is a warning.)

Actual Behavior:
error CS8987: The 'scoped' modifier of parameter 'X' doesn't match overridden or implemented member

@jcouv
Copy link
Member

jcouv commented Apr 14, 2023

Assigned to @cston to triage/advise

@jcouv jcouv added this to the 17.7 milestone Apr 17, 2023
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 17, 2023
@jaredpar jaredpar modified the milestones: 17.7, 17.8 Jul 19, 2023
@jaredpar
Copy link
Member

jaredpar commented Aug 9, 2023

Reference the library in a different project that targets net7.0, but uses language version 9

The lang version does not matter in this case for ref safety rules. From the spec

The new span safety rules will be in effect when either

  • The core library contains the feature flag indicating support for ref fields
  • The langversion value is 11 or higher

In this case by targeting net7.0 you fall into the first category so new ref safety rules are in effect. Given that the error diagnostic is expected.

@jaredpar jaredpar closed this as completed Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants