dotnet/roslyn

Compiler should report CS0208 - "Cannot declare pointer to a managed object" when managed object pointer is returned from IL with type inferrence

オープン

#33,041 opened on 2019/02/01

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersBughelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Version Used: C# 7.2

Steps to Reproduce:

  1. Have this IL and compile it
.method public hidebysig static !!0* GetPointer<T>(
      !!0 'value'
    ) cil managed
{
    ldarga 0
    conv.u
    ret
}
  1. Call it from C# as such
object obj = new object();
var objPtr = <something>.GetPointer(obj);

Expected Behavior: CS0208 - "Cannot declare pointer to a managed object"

[or, a bit more of a stretch, allow managed type pointers, such as Exception*]

Actual Behavior: Compiles and behaves like an actual object reference pointer. So objPtr->GetType() is legal and runs IMPORTANT: This only works with that type inferrence, Without var it doesn't compile

コントリビューターガイド