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

Errors for scoped differences in override indexers are missing in some cases #73384

Open
RikkiGibson opened this issue May 8, 2024 · 1 comment

Comments

@RikkiGibson
Copy link
Contributor

public ref struct RS { }

public class Base
{
    public virtual RS this[scoped RS rs] { get => default; }
    public virtual RS this[scoped RS rs, int _] { get => default; set { }}
}

public class C : Base
{
    public override RS this[RS rs] { get => default; } // error CS8987: The 'scoped' modifier of parameter 'rs' doesn't match overridden or implemented member.
    public override RS this[RS rs, int _] { get => default; set { } } // no error
}

Expected: Both commented lines have errors
Actual: Only the first commented line has an error. It seems like adding a set accessor to a similar indexer declaration removes the error.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 8, 2024
@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented May 8, 2024

I think the issue is here. It is assumed that if setter is present, then only setter needs to be checked, but for the scoped checks to actually run, there needs to be a ref or ref struct output, as well as input, which is only found on the getter.

if (overridingProperty.GetMethod is object)
{
MethodSymbol overriddenGetMethod = overriddenProperty.GetOwnOrInheritedGetMethod();
checkValidMethodOverride(
overridingProperty.GetMethod.GetFirstLocation(),
overriddenGetMethod,
overridingProperty.GetMethod,
diagnostics,
checkReturnType: true,
// Don't check parameters on the getter if there is a setter
// because they will be a subset of the setter
checkParameters: overridingProperty.SetMethod is null ||
overriddenGetMethod?.AssociatedSymbol != overriddenProperty ||
overriddenProperty.GetOwnOrInheritedSetMethod()?.AssociatedSymbol != overriddenProperty);
}
if (overridingProperty.SetMethod is object)
{
var ownOrInheritedOverriddenSetMethod = overriddenProperty.GetOwnOrInheritedSetMethod();
checkValidMethodOverride(
overridingProperty.SetMethod.GetFirstLocation(),
ownOrInheritedOverriddenSetMethod,
overridingProperty.SetMethod,
diagnostics,
checkReturnType: false,
checkParameters: true);

@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 20, 2024
@jaredpar jaredpar added this to the 17.12 milestone May 20, 2024
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

2 participants