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

OHI tests for ref readonly #17547

Merged
merged 7 commits into from
Mar 8, 2017
Merged

OHI tests for ref readonly #17547

merged 7 commits into from
Mar 8, 2017

Conversation

OmarTawfik
Copy link
Contributor

Related to #17287

@OmarTawfik OmarTawfik added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Mar 4, 2017
@OmarTawfik OmarTawfik added Area-Compilers New Language Feature - Readonly References Readonly References and removed PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Mar 5, 2017
Diagnostic(ErrorCode.ERR_ParamUnassigned, "M").WithArguments("t"));

var ns = comp.SourceModule.GlobalNamespace.GetMembers("NS").Single() as NamespaceSymbol;
// TODO...
Copy link
Contributor Author

@OmarTawfik OmarTawfik Mar 6, 2017

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

@OmarTawfik
Copy link
Contributor Author

OmarTawfik commented Mar 6, 2017

@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>
Copy link
Member

@cston cston Mar 6, 2017

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,
Copy link
Member

@cston cston Mar 6, 2017

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,
Copy link
Member

@cston cston Mar 6, 2017

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

Copy link
Contributor Author

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)

Copy link
Member

@cston cston Mar 6, 2017

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

Copy link
Contributor Author

@OmarTawfik OmarTawfik Mar 6, 2017

Choose a reason for hiding this comment

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

Ah. Good point. Will fix now.


In reply to: 104493299 [](ancestors = 104493299)


[Fact]
[CompilerTrait(CompilerFeature.ReadonlyReferences)]
public void OverloadsWithDifferentParameterModifiersShouldErrorOut_Ref_RefReadOnly()
Copy link
Member

@cston cston Mar 6, 2017

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) { }
}";
Copy link
Member

@cston cston Mar 6, 2017

Choose a reason for hiding this comment

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

Include properties. #Resolved

@cston
Copy link
Member

cston commented Mar 6, 2017

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));
}
}
}
Copy link
Contributor Author

@OmarTawfik OmarTawfik Mar 6, 2017

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

@OmarTawfik
Copy link
Contributor Author

OmarTawfik commented Mar 7, 2017

Latest version has:

  1. Responded to PR Comments
  2. Tests for properties.
  3. Tests for interfaces.
  4. Test fixes for other places where we're using unlocalized error strings.

Please let me know if you've further guidance on the wording of the error messages.
/cc @VSadov @cston @dotnet/roslyn-compiler #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>
Copy link
Member

@cston cston Mar 7, 2017

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good.


In reply to: 104703101 [](ancestors = 104703101)

@@ -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">
Copy link
Member

@cston cston Mar 7, 2017

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

Copy link
Contributor Author

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)

Copy link
Member

@cston cston Mar 7, 2017

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. Will change it back. ESL here :)


In reply to: 104769302 [](ancestors = 104769302)

@@ -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>
Copy link
Member

@cston cston Mar 7, 2017

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good.


In reply to: 104703783 [](ancestors = 104703783)

{
public virtual void Method(ref int x) { }
public virtual void Method(ref readonly int x) { }
}";
Copy link
Member

@cston cston Mar 7, 2017

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()
Copy link
Member

@cston cston Mar 7, 2017

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));
}
Copy link
Member

@cston cston Mar 7, 2017

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.


In reply to: 104743796 [](ancestors = 104743796)

// public override ref readonly int Property1 { get { return ref x; } }
Diagnostic(ErrorCode.ERR_CantChangeRefnessOfReturnOnOverride, "Property1").WithArguments("B.Property1", "A.Property1").WithLocation(10, 38));
}
}
Copy link
Member

@cston cston Mar 7, 2017

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

Copy link
Contributor Author

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");
Copy link
Member

@cston cston Mar 7, 2017

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; }
}";
Copy link
Member

@cston cston Mar 7, 2017

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

@cston
Copy link
Member

cston commented Mar 7, 2017

LGTM

@OmarTawfik
Copy link
Contributor Author

@dotnet/roslyn-compiler @VSadov can I get another sign off?

Copy link
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants