提交 94c57e4b 编写于 作者: V VSadov

Merge pull request #4417 from VSadov/fix3593

Produce an error when __makeref is used and TypedReference type is no…
......@@ -619,7 +619,7 @@ private BoundExpression BindMakeRef(MakeRefExpressionSyntax node, DiagnosticBag
bool hasErrors = argument.HasAnyErrors;
TypeSymbol typedReferenceType = this.Compilation.GetSpecialType(SpecialType.System_TypedReference);
TypeSymbol typedReferenceType = GetSpecialType(SpecialType.System_TypedReference, diagnostics, node);
if ((object)argument.Type != null && argument.Type.IsRestrictedType())
{
......
......@@ -252,6 +252,42 @@ static int M(decimal d)
var verifier = CompileAndVerify(compilation2);
}
public void NoTypedRef()
{
var source1 =
@"namespace System
{
public class Object { }
public struct Void { }
public class ValueType { }
public struct Int32 { }
public struct Decimal { }
}";
var compilation1 = CreateCompilation(source1, assemblyName: GetUniqueName());
var reference1 = MetadataReference.CreateFromStream(compilation1.EmitToStream());
var source2 =
@"
public class C1
{
public static T Read<T>()
{
T result = default(T);
var refresult = __makeref(result);
// ... method body
return result;
}
}
";
var compilation2 = CreateCompilation(source2, new[] { reference1 });
compilation2.VerifyDiagnostics(
// (7,25): error CS0518: Predefined type 'System.TypedReference' is not defined or imported
// var refresult = __makeref(result);
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "__makeref(result)").WithArguments("System.TypedReference").WithLocation(7, 25)
);
}
[WorkItem(530861, "DevDiv")]
[Fact]
public void MissingStringLengthForEach()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册