Skip to content

Commit

Permalink
Address remaining feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Apr 23, 2020
1 parent 63fe94a commit 7cce780
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,7 @@ bool isAssignedFromInitOnlySetterOnThis(BoundExpression receiver)
return false;
}

var containingMember = ContainingMemberOrLambda;
if (!(containingMember is MethodSymbol method))
if (!(ContainingMemberOrLambda is MethodSymbol method))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,6 @@ internal override bool GenerateDebugInfo

internal override bool IsDeclaredReadOnly => UnderlyingMethod.IsDeclaredReadOnly;

internal sealed override bool IsInitOnly => UnderlyingMethod.IsInitOnly;
internal override bool IsInitOnly => UnderlyingMethod.IsInitOnly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ int P2
}

[Fact]
public void ModReqOnAccessorParameter()
public void ModReqOnSetAccessorParameter()
{
string il = @"
.class public auto ansi beforefieldinit C extends System.Object
Expand Down Expand Up @@ -2184,6 +2184,67 @@ public class Derived2 : C
);
}

[Fact]
public void ModReqOnGetAccessorReturnValue()
{
string il = @"
.class public auto ansi beforefieldinit C extends System.Object
{
.method public hidebysig specialname newslot virtual instance int32 modreq(System.Runtime.CompilerServices.IsExternalInit) get_Property () cil managed
{
IL_0000: ldnull
IL_0001: throw
}
.method public hidebysig specialname newslot virtual instance void set_Property ( int32 'value' ) cil managed
{
IL_0000: ldnull
IL_0001: throw
}
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
IL_0000: ldnull
IL_0001: throw
}
.property instance int32 Property()
{
.get instance int32 modreq(System.Runtime.CompilerServices.IsExternalInit) C::get_Property()
.set instance void C::set_Property(int32)
}
}
.class public auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsExternalInit extends System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
IL_0000: ldnull
IL_0001: throw
}
}
";

string source = @"
public class Derived : C
{
public override int Property { get { throw null; } }
}
public class Derived2 : C
{
public override int Property { get { throw null; } }
}
";

var reference = CreateMetadataReferenceFromIlSource(il);
var comp = CreateCompilation(source, references: new[] { reference }, parseOptions: TestOptions.RegularPreview);
comp.VerifyDiagnostics();

var property = (PEPropertySymbol)comp.GlobalNamespace.GetMember("C.Property");
Assert.False(property.GetMethod.IsInitOnly);
Assert.False(property.SetMethod.IsInitOnly);
}

[Fact]
public void TestSyntaxFacts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ private void DecodeParameterOrThrow(ref BlobReader signatureReader, /*out*/ ref
var allowedRequiredModifiers = AllowedRequiredModifierType.System_Runtime_InteropServices_InAttribute;
if (isReturn)
{
// PROTOTYPE(init-only): can we make this more restrictive (ie. disallow aside from the return value of a setter)?
allowedRequiredModifiers |= AllowedRequiredModifierType.System_Runtime_CompilerServices_IsExternalInit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
End Function

Friend Overrides Function IsAcceptedIsExternalInitModifierType(type As TypeSymbol) As Boolean
' VB doesn't deal with init-only members.
' PROTOTYPE(init-only): VB doesn't deal with init-only members yet.
Return False
End Function

Expand Down

0 comments on commit 7cce780

Please sign in to comment.