Error in case when boolean expression

Hello!

I try to compile C# code from Visual Studio (it succesfully compiled by MS CSharp compiler), I got error: Semilocon expected.
Source code:
switch (enumerator.Current) {

  • … … … *

  •                case "--" when allowDashDash:* // Error: colon expected
    
  •                    forceValues = true;*
    
  •                    break;*
    
  •                case "--":*
    

//allowDashDash - boolean variable

RemObjects C# does not support when clause in case operator???

Thank you!

Best Regards
Igor

Hi Igor,

can i see a complete and coreect code snippet or full project for this? The code you pasted seems to have extra characters such as the *.

HI!

This is completed testcase for reproduce problem:

readme.txt (3.0 KB)
testcase.cs (409 Bytes)
testcase.elements (1.7 KB)

C# compiler from MS:
C:\temp\testcase>C:\VS2022\MSBuild\Current\Bin\Roslyn\csc.exe testcase.cs
Microsoft (R) Visual C# Compiler version 4.12.0-3.24572.7 (dfa7fc6b)
Copyright (C) Microsoft Corporation. All rights reserved.

C:\temp\testcase>testcase.exe
Starting testcase …
OK!
Finish testcase.

Remobject C# Compiler (.Net):

C:\temp\testcase>“C:\Program Files (x86)\RemObjects Software\Elements\Bin\EBuild.exe” testcase.elements
RemObjects EBuild. An open source build engine for Elements and beyond.
Copyright RemObjects Software 2016-2024. All Rights Reserved. Created by marc hoffman.
Version 12.0.0.2959 (develop) built on bajor, 20241206-130316. Commit bd32d12.
Reference ‘mscorlib’ was resolved to ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\mscorlib.dll’ for target ‘Echoes’.
Reference ‘System.Core’ was resolved to ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\System.Core.dll’ for target ‘Echoes’.

E: colon expected, got “when” [C:\temp\testcase\testcase.cs (14)]
E: ; expected, got allowDashDash [C:\temp\testcase\testcase.cs (14)]
Project ‘testcase’ failed to build.
Solution ‘testcase’ failed to build project ‘testcase’.

Best Regards
Igor Melnikov

Curious. I can’t find any reference ot this specific syntax; all I find is having a type/ car declaration before when, eg:

        switch (caseSwitch)
        {
            case int x when x > 5 || x < 0:    
                // ...
            case int x when x is > 5 or < 0:  
                // ...
        }

but not an expression/literal. But I’ll log an issue for the compiler team…

Logged as bugs://E27067.

Thank you!

After “when” clause can be any logical expession.
Boolean variable is kind of logical expression.

I mean before the when

bugs://E27067 was closed as fixed.