NerdLang / nerd

🔱 Javascript's God Mode. No VM. No Bytecode. No GC. Just native binaries.
https://nectarjs.com
MIT License
3.58k stars 127 forks source link

Switch on bool fails to compile #135

Closed DirtyHairy closed 1 year ago

DirtyHairy commented 3 years ago
switch (true) {
    case 1 < 0:
        console.log('hanni');
        break;

    case 0 < 1:
        console.log('nanni');
        break;
}

NodeJS:

$ node switch.js
nanni

Nectar:

$ nectar --run switch.js
[*] Generating source file
[*] Compiling with preset: speed
/Users/pestix/dumpster/nectar/.nectar/7j0o0/switch.cpp:322:1: error: multiple conversions from switch condition type 'NectarCore::VAR' to an integral or enumeration type
switch (__Nectar_Boolean_TRUE) {
^       ~~~~~~~~~~~~~~~~~~~~~
/Users/pestix/dumpster/nectar/.nectar/7j0o0/var_header.h:191:3: note: conversion to integral type 'int'
                operator int();
                ^
/Users/pestix/dumpster/nectar/.nectar/7j0o0/var_header.h:195:3: note: conversion to integral type 'bool'
                operator bool();
                ^
/Users/pestix/dumpster/nectar/.nectar/7j0o0/var_header.h:199:3: note: conversion to integral type 'long long'
                operator long long();
adrien-thierry commented 1 year ago

switch statement will be added very soon

adrien-thierry commented 1 year ago

Done, little "hacky" because we need to use a if/else if/else loop in C++, as C++ switch only accept const, but it's working