提交 42a8f4c0 编写于 作者: O Omar Tawfik

Added tests

上级 56764f13
......@@ -1016,20 +1016,25 @@ internal override DiagnosticInfo GetUseSiteDiagnostic()
}
return CSDiagnosticInfo.IsEmpty(result)
? InterlockedOperations.Initialize(ref _uncommonFields._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
? InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
: result;
}
private DiagnosticInfo InitializeUseSiteDiagnostic(DiagnosticInfo diagnostic)
{
Debug.Assert(!CSDiagnosticInfo.IsEmpty(diagnostic));
if (_packedFlags.IsUseSiteDiagnosticPopulated)
{
return _uncommonFields?._lazyUseSiteDiagnostic;
}
if (diagnostic != null)
{
Debug.Assert(!CSDiagnosticInfo.IsEmpty(diagnostic));
diagnostic = InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, diagnostic, CSDiagnosticInfo.EmptyErrorInfo);
}
_packedFlags.SetIsUseSiteDiagnosticPopulated();
return _uncommonFields?._lazyUseSiteDiagnostic;
return diagnostic;
}
internal override ImmutableArray<string> GetAppliedConditionalSymbols()
......
......@@ -68,7 +68,7 @@ private enum Flags : byte
var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
Debug.Assert(propertyParams.Length > 0);
var isBad = propEx != null;
var isBad = false;
var returnInfo = propertyParams[0];
PEPropertySymbol result;
......@@ -81,7 +81,7 @@ private enum Flags : byte
result = new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder, out isBad);
}
if (isBad)
if (propEx != null || isBad)
{
result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
}
......
......@@ -35,7 +35,9 @@ internal static class CustomModifierUtils
// have already been compared.
MethodSymbol constructedSourceMethod = sourceMethod.ConstructIfGeneric(destinationMethod.TypeArguments);
customModifiers = CustomModifiersTuple.Create(constructedSourceMethod.ReturnTypeCustomModifiers, constructedSourceMethod.RefCustomModifiers);
customModifiers = CustomModifiersTuple.Create(
constructedSourceMethod.ReturnTypeCustomModifiers,
destinationMethod.ReturnsByRef || destinationMethod.ReturnsByRefReadonly ? constructedSourceMethod.RefCustomModifiers : ImmutableArray<CustomModifier>.Empty);
parameters = CopyParameterCustomModifiers(constructedSourceMethod.Parameters, destinationMethod.Parameters, alsoCopyParamsModifier);
......
......@@ -231,7 +231,8 @@ internal override LexicalSortKey GetLexicalSortKey()
private sealed class InvokeMethod : SourceDelegateMethodSymbol
{
private readonly RefKind refKind;
private readonly RefKind _refKind;
private readonly ImmutableArray<CustomModifier> _refCustomModifiers;
internal InvokeMethod(
SourceMemberContainerTypeSymbol delegateType,
......@@ -242,14 +243,14 @@ private sealed class InvokeMethod : SourceDelegateMethodSymbol
DiagnosticBag diagnostics)
: base(delegateType, returnType, syntax, MethodKind.DelegateInvoke, DeclarationModifiers.Virtual | DeclarationModifiers.Public)
{
this.refKind = refKind;
this._refKind = refKind;
SyntaxToken arglistToken;
var parameters = ParameterHelpers.MakeParameters(
binder, this, syntax.ParameterList, out arglistToken,
allowRefOrOut: true,
allowThis: false,
addIsConstModifier: false,
addIsConstModifier: true,
diagnostics: diagnostics);
if (arglistToken.Kind() == SyntaxKind.ArgListKeyword)
......@@ -260,6 +261,16 @@ private sealed class InvokeMethod : SourceDelegateMethodSymbol
diagnostics.Add(ErrorCode.ERR_IllegalVarArgs, new SourceLocation(arglistToken));
}
if (_refKind == RefKind.RefReadOnly)
{
var isConstType = binder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
_refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType));
}
else
{
_refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
}
InitializeParameters(parameters);
}
......@@ -270,7 +281,7 @@ public override string Name
internal override RefKind RefKind
{
get { return refKind; }
get { return _refKind; }
}
internal override LexicalSortKey GetLexicalSortKey()
......@@ -288,7 +299,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
{
base.AfterAddingTypeMembersChecks(conversions, diagnostics);
if (refKind == RefKind.RefReadOnly)
if (_refKind == RefKind.RefReadOnly)
{
var syntax = (DelegateDeclarationSyntax)SyntaxRef.GetSyntax();
DeclaringCompilation.EnsureIsReadOnlyAttributeExists(diagnostics, syntax.ReturnType.GetLocation(), modifyCompilationForRefReadOnly: true);
......@@ -296,6 +307,8 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
ParameterHelpers.EnsureIsReadOnlyAttributeExists(Parameters, diagnostics, modifyCompilationForRefReadOnly: true);
}
public override ImmutableArray<CustomModifier> RefCustomModifiers => _refCustomModifiers;
}
private sealed class BeginInvokeMethod : SourceDelegateMethodSymbol
......
......@@ -326,7 +326,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
out _lazyParameters, alsoCopyParamsModifier: true);
}
}
else if (_refKind == RefKind.RefReadOnly && (IsVirtual || IsAbstract))
else if (_refKind == RefKind.RefReadOnly)
{
var isConstType = withTypeParamsBinder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
......
......@@ -273,7 +273,7 @@ internal sealed class SourcePropertySymbol : PropertySymbol, IAttributeTargetSym
_lazyParameters = CustomModifierUtils.CopyParameterCustomModifiers(overriddenOrImplementedProperty.Parameters, _lazyParameters, alsoCopyParamsModifier: isOverride);
}
}
else if (_refKind == RefKind.RefReadOnly && (IsVirtual || IsAbstract))
else if (_refKind == RefKind.RefReadOnly)
{
var isConstType = bodyBinder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.Type);
......
......@@ -202,7 +202,7 @@ private TypeSymbol DecodeTypeOrThrow(ref BlobReader ppSig, SignatureTypeCode typ
int countOfSizes;
int countOfLowerBounds;
modifiers = DecodeModifiersOrThrow(ref ppSig, out typeCode);
modifiers = DecodeModifiersOrThrow(ref ppSig, AllowedRequiredModifierType.None, out typeCode, out _);
typeSymbol = DecodeTypeOrThrow(ref ppSig, typeCode, out refersToNoPiaLocalType);
if (!ppSig.TryReadCompressedInteger(out countOfDimensions) ||
!ppSig.TryReadCompressedInteger(out countOfSizes))
......@@ -285,13 +285,13 @@ private TypeSymbol DecodeTypeOrThrow(ref BlobReader ppSig, SignatureTypeCode typ
break;
case SignatureTypeCode.SZArray:
modifiers = DecodeModifiersOrThrow(ref ppSig, out typeCode);
modifiers = DecodeModifiersOrThrow(ref ppSig, AllowedRequiredModifierType.None, out typeCode, out _);
typeSymbol = DecodeTypeOrThrow(ref ppSig, typeCode, out refersToNoPiaLocalType);
typeSymbol = GetSZArrayTypeSymbol(typeSymbol, modifiers);
break;
case SignatureTypeCode.Pointer:
modifiers = DecodeModifiersOrThrow(ref ppSig, out typeCode);
modifiers = DecodeModifiersOrThrow(ref ppSig, AllowedRequiredModifierType.None, out typeCode, out _);
typeSymbol = DecodeTypeOrThrow(ref ppSig, typeCode, out refersToNoPiaLocalType);
typeSymbol = MakePointerTypeSymbol(typeSymbol, modifiers);
break;
......@@ -350,7 +350,7 @@ private TypeSymbol DecodeGenericTypeInstanceOrThrow(ref BlobReader ppSig, out bo
{
bool argumentRefersToNoPia;
SignatureTypeCode typeCode;
ImmutableArray<ModifierInfo<TypeSymbol>> modifiers = DecodeModifiersOrThrow(ref ppSig, out typeCode);
ImmutableArray<ModifierInfo<TypeSymbol>> modifiers = DecodeModifiersOrThrow(ref ppSig, AllowedRequiredModifierType.None, out typeCode, out _);
argumentsBuilder.Add(KeyValuePair.Create(DecodeTypeOrThrow(ref ppSig, typeCode, out argumentRefersToNoPia), modifiers));
argumentRefersToNoPiaLocalTypeBuilder.Add(argumentRefersToNoPia);
}
......@@ -670,52 +670,18 @@ private TypeSymbol GetTypeOfTypeDef(TypeDefinitionHandle typeDef, out bool isNoP
}
}
/// <exception cref="UnsupportedSignatureContent">If the encoded type is invalid.</exception>
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private ImmutableArray<ModifierInfo<TypeSymbol>> DecodeModifiersOrThrow(ref BlobReader signatureReader, out SignatureTypeCode typeCode)
{
ArrayBuilder<ModifierInfo<TypeSymbol>> modifiers = null;
for (;;)
{
typeCode = signatureReader.ReadSignatureTypeCode();
if (typeCode == SignatureTypeCode.RequiredModifier)
{
throw new UnsupportedSignatureContent();
}
if (typeCode == SignatureTypeCode.OptionalModifier)
{
ModifierInfo<TypeSymbol> modifier = new ModifierInfo<TypeSymbol>(true, DecodeModifierTypeOrThrow(ref signatureReader));
if (modifiers == null)
{
modifiers = ArrayBuilder<ModifierInfo<TypeSymbol>>.GetInstance();
}
modifiers.Add(modifier);
continue;
}
break;
}
return modifiers?.ToImmutableAndFree() ?? default(ImmutableArray<ModifierInfo<TypeSymbol>>);
}
/// <exception cref="UnsupportedSignatureContent">If the encoded type is invalid.</exception>
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private ImmutableArray<ModifierInfo<TypeSymbol>> DecodeModifiersOrThrow(
ref BlobReader signatureReader,
AllowedRequiredModifierType allowedRequiredModifierType,
out SignatureTypeCode typeCode,
Func<TypeSymbol, bool> acceptRequiredModifier,
out bool requiredModifierFound)
{
requiredModifierFound = false;
ArrayBuilder<ModifierInfo<TypeSymbol>> modifiers = null;
for (;;)
for (; ; )
{
typeCode = signatureReader.ReadSignatureTypeCode();
bool isOptional;
......@@ -735,10 +701,21 @@ private ImmutableArray<ModifierInfo<TypeSymbol>> DecodeModifiersOrThrow(ref Blob
TypeSymbol type = DecodeModifierTypeOrThrow(ref signatureReader);
// if it is a required modifier, make sure the compiler supports this modifier type
if (!isOptional)
{
if (acceptRequiredModifier(type))
var isAllowed = false;
switch (allowedRequiredModifierType)
{
case AllowedRequiredModifierType.System_Runtime_CompilerServices_IsConst:
isAllowed = IsAcceptedIsConstModifierType(type);
break;
case AllowedRequiredModifierType.System_Runtime_CompilerServices_Volatile:
isAllowed = IsAcceptedVolatileModifierType(type);
break;
}
if (isAllowed)
{
requiredModifierFound = true;
}
......@@ -903,7 +880,7 @@ internal LocalInfo<TypeSymbol> DecodeLocalVariableOrThrow(ref BlobReader signatu
{
SignatureTypeCode typeCode;
var customModifiers = DecodeModifiersOrThrow(ref signatureReader, out typeCode);
var customModifiers = DecodeModifiersOrThrow(ref signatureReader, AllowedRequiredModifierType.None, out typeCode, out _);
var constraints = LocalSlotConstraints.None;
TypeSymbol typeSymbol;
......@@ -944,7 +921,7 @@ internal void DecodeLocalConstantBlobOrThrow(ref BlobReader sigReader, out TypeS
{
SignatureTypeCode typeCode;
var customModifiers = DecodeModifiersOrThrow(ref sigReader, out typeCode);
var customModifiers = DecodeModifiersOrThrow(ref sigReader, AllowedRequiredModifierType.None, out typeCode, out _);
if (typeCode == SignatureTypeCode.TypeHandle)
{
......@@ -1150,16 +1127,17 @@ internal ImmutableArray<LocalInfo<TypeSymbol>> GetLocalInfo(StandaloneSignatureH
/// <exception cref="UnsupportedSignatureContent">If the encoded parameter type is invalid.</exception>
private void DecodeParameterOrThrow(ref BlobReader signatureReader, /*out*/ ref ParamInfo<TypeSymbol> info)
{
bool refersToNoPiaLocalType;
SignatureTypeCode typeCode;
info.CustomModifiers = DecodeModifiersOrThrow(ref signatureReader, out typeCode, IsAcceptedIsConstModifierType, out bool isConstFound);
info.CustomModifiers = DecodeModifiersOrThrow(
ref signatureReader,
AllowedRequiredModifierType.System_Runtime_CompilerServices_IsConst,
out SignatureTypeCode typeCode,
out bool isConstFound);
if (typeCode == SignatureTypeCode.ByReference)
{
info.IsByRef = true;
info.RefCustomModifiers = info.CustomModifiers;
info.CustomModifiers = DecodeModifiersOrThrow(ref signatureReader, out typeCode);
info.CustomModifiers = DecodeModifiersOrThrow(ref signatureReader, AllowedRequiredModifierType.None, out typeCode, out _);
}
else if (isConstFound)
{
......@@ -1167,7 +1145,7 @@ private void DecodeParameterOrThrow(ref BlobReader signatureReader, /*out*/ ref
throw new UnsupportedSignatureContent();
}
info.Type = DecodeTypeOrThrow(ref signatureReader, typeCode, out refersToNoPiaLocalType);
info.Type = DecodeTypeOrThrow(ref signatureReader, typeCode, out _);
}
// MetaImport::DecodeMethodSignature
......@@ -1907,11 +1885,13 @@ protected TypeSymbol DecodeFieldSignature(ref BlobReader signatureReader, out bo
try
{
SignatureTypeCode typeCode;
customModifiers = DecodeModifiersOrThrow(ref signatureReader, out typeCode, IsAcceptedVolatileModifierType, out isVolatile);
customModifiers = DecodeModifiersOrThrow(
ref signatureReader,
AllowedRequiredModifierType.System_Runtime_CompilerServices_Volatile,
out typeCode,
out isVolatile);
// get the type
bool refersToNoPiaLocalType;
return DecodeTypeOrThrow(ref signatureReader, typeCode, out refersToNoPiaLocalType);
return DecodeTypeOrThrow(ref signatureReader, typeCode, out _);
}
catch (UnsupportedSignatureContent)
{
......@@ -2426,5 +2406,12 @@ internal bool DoesSignatureMatchEvent(TypeSymbol eventType, ParamInfo<TypeSymbol
var methodParam = methodParams[1];
return !methodParam.IsByRef && methodParam.Type.Equals(eventType);
}
private enum AllowedRequiredModifierType
{
None,
System_Runtime_CompilerServices_Volatile,
System_Runtime_CompilerServices_IsConst,
}
}
}
......@@ -1094,18 +1094,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
End If
Return If(result Is ErrorFactory.EmptyErrorInfo,
InterlockedOperations.Initialize(_uncommonFields._lazyUseSiteErrorInfo, Nothing, ErrorFactory.EmptyErrorInfo),
InterlockedOperations.Initialize(AccessUncommonFields()._lazyUseSiteErrorInfo, Nothing, ErrorFactory.EmptyErrorInfo),
result)
End Function
Private Function InitializeUseSiteErrorInfo(errorInfo As DiagnosticInfo) As DiagnosticInfo
Debug.Assert(errorInfo IsNot ErrorFactory.EmptyErrorInfo)
If _packedFlags.IsUseSiteDiagnosticPopulated Then
Return _uncommonFields?._lazyUseSiteErrorInfo
End If
If errorInfo IsNot Nothing Then
Debug.Assert(errorInfo IsNot ErrorFactory.EmptyErrorInfo)
errorInfo = InterlockedOperations.Initialize(AccessUncommonFields()._lazyUseSiteErrorInfo, errorInfo, ErrorFactory.EmptyErrorInfo)
End If
_packedFlags.SetIsUseSiteDiagnosticPopulated()
Return _uncommonFields?._lazyUseSiteErrorInfo
Return errorInfo
End Function
Friend Overrides ReadOnly Property ObsoleteAttributeData As ObsoleteAttributeData
......
......@@ -9,7 +9,33 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Symbols.Metadata
Inherits BasicTestBase
<Fact>
Public Sub NonVirtualReadOnlySignaturesAreRead()
Public Sub ReadOnlySignaturesAreRead_Methods_Parameters_Static()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
public static void M(ref readonly int x)
{
System.Console.WriteLine(x);
}
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim x = 5
TestRef.M(x)
End Sub
End Class
</file>
</compilation>
CompileAndVerify(source, additionalRefs:={reference}, expectedOutput:="5")
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreRead_Methods_Parameters_NoModifiers()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
......@@ -35,6 +61,61 @@ End Class
CompileAndVerify(source, additionalRefs:={reference}, expectedOutput:="5")
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreRead_Indexers_Parameters_NoModifiers()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
public int this[ref readonly int p]
{
set
{
System.Console.WriteLine(p);
}
}
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim x = 5
Dim obj = New TestRef()
obj(x) = 0
End Sub
End Class
</file>
</compilation>
CompileAndVerify(source, additionalRefs:={reference}, expectedOutput:="5")
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreRead_Operators_Constructors()
Dim reference = CreateCSharpCompilation("
public struct TestRef
{
public TestRef(ref readonly int value)
{
System.Console.WriteLine(value);
}
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim obj1 = New TestRef(4)
End Sub
End Class
</file>
</compilation>
CompileAndVerify(source, additionalRefs:={reference}, expectedOutput:="4")
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Methods_Parameters_Virtual()
Dim reference = CreateCSharpCompilation("
......@@ -68,6 +149,35 @@ BC30657: 'M' has a return type that is not supported or parameter types that are
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Methods_Parameters_Abstract()
Dim reference = CreateCSharpCompilation("
public abstract class TestRef
{
public abstract void M(ref readonly int x);
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(obj As TestRef)
Dim x = 5
obj.M(x)
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30657: 'M' has a return type that is not supported or parameter types that are not supported.
obj.M(x)
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_Virtual()
Dim reference = CreateCSharpCompilation("
......@@ -101,6 +211,99 @@ BC30657: 'M' has a return type that is not supported or parameter types that are
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_Abstract()
Dim reference = CreateCSharpCompilation("
public abstract class TestRef
{
public abstract ref readonly int M();
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(obj As TestRef)
obj.M()
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30657: 'M' has a return type that is not supported or parameter types that are not supported.
obj.M()
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_Static()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
private static int value = 0;
public static ref readonly int M()
{
return ref value;
}
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
TestRef.M()
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30657: 'M' has a return type that is not supported or parameter types that are not supported.
TestRef.M()
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_NoModifiers()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
private int value = 0;
public ref readonly int M()
{
return ref value;
}
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim obj = New TestRef()
obj.M()
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30657: 'M' has a return type that is not supported or parameter types that are not supported.
obj.M()
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Properties_Virtual()
Dim reference = CreateCSharpCompilation("
......@@ -131,6 +334,152 @@ BC30643: Property 'P' is of an unsupported type.
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Properties_Static()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
private static int value = 0;
public static ref readonly int P => ref value;
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim value = TestRef.P
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'P' is of an unsupported type.
Dim value = TestRef.P
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Properties_NoModifiers()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
private int value = 0;
public ref readonly int P => ref value;
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim obj = New TestRef()
Dim value = obj.P
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'P' is of an unsupported type.
Dim value = obj.P
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Properties_Abstract()
Dim reference = CreateCSharpCompilation("
public abstract class TestRef
{
public abstract ref readonly int P { get; }
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(obj As TestRef)
Dim value = obj.P
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'P' is of an unsupported type.
Dim value = obj.P
~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Indexers_Parameters_Virtual()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
public virtual int this[ref readonly int p] => 0;
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main()
Dim p = 0
Dim obj = New TestRef()
Dim value = obj(p)
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'TestRef.Item(p As )' is of an unsupported type.
Dim value = obj(p)
~~~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Indexers_Parameters_Abstract()
Dim reference = CreateCSharpCompilation("
public abstract class TestRef
{
public abstract int this[ref readonly int p] { set; }
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(obj As TestRef)
Dim p = 0
Dim value = obj(p)
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'TestRef.Item(p As )' is of an unsupported type.
Dim value = obj(p)
~~~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Indexers_ReturnTypes_Virtual()
Dim reference = CreateCSharpCompilation("
......@@ -162,11 +511,40 @@ BC30643: Property 'TestRef.Item(p As )' is of an unsupported type.
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Indexers_Parameters_Virtual()
Public Sub ReadOnlySignaturesAreNotSupported_Indexers_ReturnTypes_Abstract()
Dim reference = CreateCSharpCompilation("
public abstract class TestRef
{
public abstract ref readonly int this[int p] { get; }
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(obj As TestRef)
Dim value = obj(0)
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'TestRef.Item(p As )' is of an unsupported type.
Dim value = obj(0)
~~~
</expected>)
End Sub
<Fact>
Public Sub ReadOnlySignaturesAreNotSupported_Indexers_ReturnTypes_NoModifiers()
Dim reference = CreateCSharpCompilation("
public class TestRef
{
public virtual int this[ref readonly int p] => 0;
private int value = 0;
public ref readonly int this[int p] => ref value;
}", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
......@@ -174,9 +552,8 @@ public class TestRef
<file>
Class Test
Shared Sub Main()
Dim p = 0
Dim obj = New TestRef()
Dim value = obj(p)
Dim value = obj(0)
End Sub
End Class
</file>
......@@ -186,10 +563,63 @@ End Class
AssertTheseDiagnostics(compilation, <expected>
BC30643: Property 'TestRef.Item(p As )' is of an unsupported type.
Dim value = obj(p)
Dim value = obj(0)
~~~
</expected>)
End Sub
<Fact>
Public Sub UsingLambdasOfRefReadOnlyDelegatesIsNotSupported_Parameters()
Dim reference = CreateCSharpCompilation("
public delegate void D(ref readonly int p);
", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(lambda As D)
Dim x = 0
lambda(x)
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30657: 'D' has a return type that is not supported or parameter types that are not supported.
lambda(x)
~~~~~~
</expected>)
End Sub
<Fact>
Public Sub UsingLambdasOfRefReadOnlyDelegatesIsNotSupported_ReturnTypes()
Dim reference = CreateCSharpCompilation("
public delegate ref readonly int D();
", parseOptions:=New CSharpParseOptions(CSharp.LanguageVersion.Latest)).EmitToImageReference()
Dim source =
<compilation>
<file>
Class Test
Shared Sub Main(lambda As D)
Dim x = lambda()
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib(source, references:={reference})
AssertTheseDiagnostics(compilation, <expected>
BC30657: 'D' has a return type that is not supported or parameter types that are not supported.
Dim x = lambda()
~~~~~~
</expected>)
End Sub
End Class
End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册