-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
OHI tests for ref readonly #17547
OHI tests for ref readonly #17547
Conversation
Diagnostic(ErrorCode.ERR_ParamUnassigned, "M").WithArguments("t")); | ||
|
||
var ns = comp.SourceModule.GlobalNamespace.GetMembers("NS").Single() as NamespaceSymbol; | ||
// TODO... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed? #Closed
@VSadov @dotnet/roslyn-compiler #Resolved |
@@ -5005,4 +5002,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_AttributesInLocalFuncDecl" xml:space="preserve"> | |||
<value>Attributes are not allowed on local function parameters or type parameters</value> | |||
</data> | |||
<data name="IDS_SK_CONSTRUCTOR" xml:space="preserve"> | |||
<value>constructor</value> | |||
</data> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps move beside other IDS_SK_
items, line 280 or so. #Resolved
@@ -130,6 +130,7 @@ internal enum MessageID | |||
|
|||
IDS_FeatureReadonlyReferences = MessageBase + 12718, | |||
|
|||
IDS_SK_CONSTRUCTOR = MessageBase + 12719, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Group with other IDS_SK_
values in the file and use value in the same range, say = MessageBase + 2013
. #Resolved
@@ -5084,7 +5084,7 @@ internal enum ErrorCode | |||
ERR_ExpressionTreeContainsBadCoalesce = 845, | |||
ERR_ArrayInitializerExpected = 846, | |||
ERR_ArrayInitializerIncorrectLength = 847, | |||
ERR_OverloadRefOutCtor = 851, | |||
ERR_OverloadRefKindCtor = 851, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point: The original enum value did not change. #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Is that needed? Just refactoring the name to indicate it is used now for all ref kinds instead of ref/out.
In reply to: 104460669 [](ancestors = 104460669)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instance of ErrorCode
should probably match the original ErrorCode
. In other words, we should rename both instances of ERR_OverloadRefOutCtor
or neither. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
[Fact] | ||
[CompilerTrait(CompilerFeature.ReadonlyReferences)] | ||
public void OverloadsWithDifferentParameterModifiersShouldErrorOut_Ref_RefReadOnly() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider dropping ShouldErrorOut
, WillErrorOut
, etc. from test method names, for consistency with other tests. #Resolved
{ | ||
public override void Method1(ref readonly int x) { } | ||
public override void Method2(ref int x) { } | ||
}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include properties. #Resolved
Please test interface implementations, if interfaces are also covered by this PR. #Resolved |
Diagnostic(ErrorCode.ERR_OverrideNotExpected, "Method1").WithArguments("ChildClass.Method1(ref readonly int)").WithLocation(9, 26)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: add tests for method return type mismatch by refness #Resolved
<data name="ERR_CantChangeRefReturnOnOverride" xml:space="preserve"> | ||
<value>'{0}' must {2}return by reference to match overridden member '{1}'</value> | ||
<data name="ERR_CantChangeRefnessOfReturnOnOverride" xml:space="preserve"> | ||
<value>Reference signature of the return type of '{0}' does not match overridden member '{1}'</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference signature
sounds like a new term, and we should avoid adding terminology if not necessary. Perhaps"'{0}' must match by reference return of overridden member '{1}'"
. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -4729,8 +4729,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_RefPropertyCannotHaveSetAccessor" xml:space="preserve"> | |||
<value>Properties which return by reference cannot have set accessors</value> | |||
</data> | |||
<data name="ERR_CantChangeRefReturnOnOverride" xml:space="preserve"> | |||
<value>'{0}' must {2}return by reference to match overridden member '{1}'</value> | |||
<data name="ERR_CantChangeRefnessOfReturnOnOverride" xml:space="preserve"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename of ERR_CantChangeRefReturnOnOverride
seems unnecessary. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it might be "cannot change ref readonly return" as well. Need to indicate that this involves other kinds of refness as well.
In reply to: 104703333 [](ancestors = 104703333)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, both names capture that equally. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -4742,7 +4742,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<value>The return expression must be of type '{0}' because this method returns by reference</value> | |||
</data> | |||
<data name="ERR_CloseUnimplementedInterfaceMemberWrongRefReturn" xml:space="preserve"> | |||
<value>'{0}' does not implement interface member '{1}'. '{2}' cannot implement '{1}' because it does not return by {3}</value> | |||
<value>'{0}' does not implement interface member '{1}'. '{2}' cannot implement '{1}' because it does not have the matching return type reference signature.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "... does not have matching return by reference"
. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
public virtual void Method(ref int x) { } | ||
public virtual void Method(ref readonly int x) { } | ||
}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing abstract
and virtual
so it's clear the overload error does not depend on virtual methods. Same comment for test below. #Resolved
|
||
[Fact] | ||
[CompilerTrait(CompilerFeature.ReadonlyReferences)] | ||
public void HidingMethodWithRefReadOnlyParameterWillProduceAWarning() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider dropping Will
and WillNotProduceAWarning
suffixes, for consistency with other tests. (The tests themselves indicate whether a warning is produced.) #Resolved
// (6,11): error CS0535: 'B' does not implement interface member 'A.M(ref readonly int)' | ||
// class B : A | ||
Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "A").WithArguments("B", "A.M(ref readonly int)").WithLocation(6, 11)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we testing different ref return type, for methods and properties? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// public override ref readonly int Property1 { get { return ref x; } } | ||
Diagnostic(ErrorCode.ERR_CantChangeRefnessOfReturnOnOverride, "Property1").WithArguments("B.Property1", "A.Property1").WithLocation(10, 38)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are ref readonly
parameters supported for indexers? object this[ref readonly int i] { get; set; }
#Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add tests for both indexers parameters and return types.
In reply to: 104744994 [](ancestors = 104744994)
var bClass = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("B"); | ||
|
||
var aMethod = aClass.GetMember<MethodSymbol>("M"); | ||
var bMethod = bClass.GetMember<MethodSymbol>("M"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point: Can use var aMethod = comp.GetMember<MethodSymbol>("A.M");
in each case. #Resolved
class B : A | ||
{ | ||
public ref readonly int M() { return ref x; } | ||
}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider testing the warning is produced, even when ref return is different. #Resolved
LGTM |
@dotnet/roslyn-compiler @VSadov can I get another sign off? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Related to #17287