question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch case issue

See original GitHub issue

Hello,

 protected override void Run()
        {
            try
            {
                switch (Logged)
                {
                    case false:

                        break;

                    case true:
                        //LOGGED
                        Console.Write(UserLevel.TypeUser() + userLogged + "~ " + current_directory + "> ");
                        var cmd = Console.ReadLine();
                        Shell.Interpreter.Interpret(cmd);
                        Console.WriteLine();

                        break;
                }
            }
            catch (Exception ex)
            {
                running = false;
                Crash.StopKernel(ex);
            }

        }

When I did this switch case, I had that error:

Error: Exception: System.Exception: Error compiling method 'SystemVoidAlve_OSKernelRun': System.Exception: Error interpreting stacktypes for IL_000F: Beq ---> System.Exception: Comparing types 'System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' and 'System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' not supported!
2>       at Cosmos.IL2CPU.ILOpCodes.OpBranch.DoInterpretStackTypes(Boolean& aSituationChanged) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCodes\OpBranch.cs:line 173
2>       at Cosmos.IL2CPU.ILOpCode.InterpretStackTypes(IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 413
2>       --- End of inner exception stack trace ---
2>       at Cosmos.IL2CPU.ILOpCode.InterpretStackTypes(IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 417
2>       at Cosmos.IL2CPU.ILOpCode.InterpretInstruction(ILOpCode xNextOpCode, IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 470
2>       at Cosmos.IL2CPU.ILOpCode.InterpretInstruction(Int32 aPosition, IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 464
2>       at Cosmos.IL2CPU.ILOpCode.DoInterpretNextInstructionStackTypes(IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 446
2>       at Cosmos.IL2CPU.ILOpCode.InterpretStackTypes(IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 423
2>       at Cosmos.IL2CPU.ILOpCode.InterpretInstruction(ILOpCode xNextOpCode, IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 470
2>       at Cosmos.IL2CPU.ILOpCode.InterpretInstruction(Int32 aPosition, IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 464
2>       at Cosmos.IL2CPU.ILOpCode.DoInterpretNextInstructionStackTypes(IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 446
2>       at Cosmos.IL2CPU.ILOpCode.InterpretStackTypes(IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 423
2>       at Cosmos.IL2CPU.ILOpCode.InterpretInstruction(ILOpCode xNextOpCode, IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 470
2>       at Cosmos.IL2CPU.ILOpCode.InterpretInstructionIfNotYetProcessed(Int32 aPosition, IDictionary`2 aOpCodes, Stack`1 aStack, Boolean& aSituationChanged, Int32 aMaxRecursionDepth) in C:\Users\dacru\Documents\Visual Studio 2017\Projects\Alve-Cosmos\Cosmos\source\Cosmos.IL2CPU\ILOpCode.cs:line 455
2>       at Cosmos.IL2CPU.ILOpCodes.OpBranch.DoInterpretNextInstruc

And on ILSpy I have this:

IL_000d: ldloc.0 //local 0 is a bool
IL_000e: ldc.i4.1
IL_000f: beq.s IL_0015

I solved the problem with the help of @jp2masa using a if/else !

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
frenzibytecommented, Sep 13, 2017

Problem has been fixed with the help of @jp2masa 👍 Problem is comparing types int and bool code wasn’t there so the method didn’t return Compiler thinks that this is not supported so that’s why it is not working

1reaction
djlw78commented, Aug 12, 2017

More native code issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

switch - JavaScript - MDN Web Docs - Mozilla
The switch statement evaluates an expression, matching the expression's value against a series of case clauses, and executes statements ...
Read more >
Don't Be a Basic Coder And Use 5 Possibilities to Avoid ...
You probably understood switch cases because they have a low learning curve and result in quite a comfortable usage. It is a default...
Read more >
Strange problem with switch case with arduino
One thing that messes up switch/case statements is an initialized local variable in a case.
Read more >
In a switch statement, why are all the cases being executed?
I see this question is over 8 years old, but this answer should help anyone landing on this page. Firstly lets's understand how...
Read more >
What's wrong with the switch statement in JavaScript?
The statement can make calls in one case, and in others, mutate or apply transforms to data in another. In another scenario, one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found