If (false == true) executes block when throwing exception is inside

后端 未结 2 438
萌比男神i
萌比男神i 2020-12-23 08:41

I have a rather strange problem that is occurring.

This is my code:

private async Task BreakExpectedLogic()
{
    bool test = false;
    if (test ==          


        
2条回答
  •  孤城傲影
    2020-12-23 09:07

    Just an addendum to the answer, I've recently encountered the same issue, and looked to the actual x86 code in the debugger, and it was generated in a weird way like this (simplified):

    // if (...) {
    0001: jne 0006
    ...
    0006: jmp 0007
    // }
    0007: ret
    

    So instead of directly jumping to the last instructions of the method, it does double jump, where I believe the second unconditional jump is mistakenly recognized as a part of the code inside if block.

    So I would speculate that this bug might be related to JIT compiler.

提交回复
热议问题