提交 ae877468 编写于 作者: J Julien Couvreur 提交者: GitHub

Use error=true in Obsolete attribute on IsByRefLikeAttribute for ref struct (#22492)

上级 f39838b5
......@@ -1135,8 +1135,8 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
{
AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_ObsoleteAttribute__ctor,
ImmutableArray.Create(
new TypedConstant(compilation.GetSpecialType(SpecialType.System_String), TypedConstantKind.Primitive, PEModule.ByRefLikeMarker),
new TypedConstant(compilation.GetSpecialType(SpecialType.System_Boolean), TypedConstantKind.Primitive, false)),
new TypedConstant(compilation.GetSpecialType(SpecialType.System_String), TypedConstantKind.Primitive, PEModule.ByRefLikeMarker), // message
new TypedConstant(compilation.GetSpecialType(SpecialType.System_Boolean), TypedConstantKind.Primitive, true)), // error=true
isOptionalUse: true));
}
}
......
......@@ -870,6 +870,36 @@ public struct S1 {}
);
}
[Fact]
public void ObsoleteHasErrorEqualsTrue()
{
var text = @"public ref struct S {}";
CompileAndVerify(text, verify: false, symbolValidator: module =>
{
var type = module.ContainingAssembly.GetTypeByMetadataName("S");
Assert.True(type.IsByRefLikeType);
var attributes = type.GetAttributes();
Assert.Equal(2, attributes.Length);
var attributeType = attributes[0].AttributeClass;
Assert.Equal("System.Runtime.CompilerServices.IsByRefLikeAttribute", attributeType.ToDisplayString());
var assemblyName = module.ContainingAssembly.Name;
Assert.Equal(assemblyName, attributeType.ContainingAssembly.Name);
var accessibility = Accessibility.Internal;
Assert.Equal(accessibility, attributeType.DeclaredAccessibility);
var attribute = attributes[1];
Assert.Equal("System.ObsoleteAttribute", attribute.AttributeClass.ToDisplayString());
TypedConstant[] constructorArguments = attribute.ConstructorArguments.ToArray();
Assert.Equal(2, constructorArguments.Length);
Assert.Equal("Types with embedded references are not supported in this version of your compiler.", constructorArguments[0].Value);
Assert.Equal(true, constructorArguments[1].Value);
});
}
[Fact]
public void ObsoleteInWrongPlaces()
{
......@@ -1032,7 +1062,7 @@ namespace System
var attribute = attributes[1];
Assert.Equal("System.ObsoleteAttribute", attribute.AttributeClass.ToDisplayString());
Assert.Equal("Types with embedded references are not supported in this version of your compiler.", attribute.ConstructorArguments.ElementAt(0).Value);
Assert.Equal(false, attribute.ConstructorArguments.ElementAt(1).Value);
Assert.Equal(true, attribute.ConstructorArguments.ElementAt(1).Value); // error=true
}
}
......
......@@ -1469,6 +1469,39 @@ BC40000: 'Public Sub Bar()' is obsolete: 'hi'.
compilation3.AssertTheseDiagnostics(expected2)
End Sub
<Fact>
<WorkItem(22447, "https://github.com/dotnet/roslyn/issues/22447")>
Public Sub TestRefLikeType()
Dim csSource = <![CDATA[
public ref struct S { }
]]>
Dim csCompilation = CreateCSharpCompilation("Dll1", csSource.Value, parseOptions:=New CSharp.CSharpParseOptions(CSharp.LanguageVersion.CSharp7_2))
Dim ref = csCompilation.EmitToImageReference()
Dim vbSource =
<compilation>
<file name="test.vb"><![CDATA[
Module Program
Sub M(s As S)
End Sub
End Module
]]>
</file>
</compilation>
Dim vbCompilation = CreateCompilationWithMscorlibAndVBRuntimeAndReferences(vbSource, {ref})
vbCompilation.AssertTheseDiagnostics((<![CDATA[
BC30668: 'S' is obsolete: 'Types with embedded references are not supported in this version of your compiler.'.
Sub M(s As S)
~
]]>))
vbCompilation.VerifyDiagnostics(
Diagnostic(ERRID.ERR_UseOfObsoleteSymbol2, "S").WithArguments("S", "Types with embedded references are not supported in this version of your compiler.").WithLocation(2, 16)
)
End Sub
<Fact(), WorkItem(858839, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858839")>
Public Sub Bug858839_1()
Dim source1 =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册