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 建立於 2019年2月1日
Area-CompilersBughelp wanted
倉庫指標
- 星標
- (20,414 顆星)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 256 個 PR)
描述
Version Used: C# 7.2
Steps to Reproduce:
- Have this IL and compile it
.method public hidebysig static !!0* GetPointer<T>(
!!0 'value'
) cil managed
{
ldarga 0
conv.u
ret
}
- 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