chiselstrike icon indicating copy to clipboard operation
chiselstrike copied to clipboard

Default boolean values in model are not handled correctly

Open honzasp opened this issue 3 years ago • 4 comments

In this code, the field isAwesome has default value true:

import { ChiselEntity } from '@chiselstrike/api';

export class Human extends ChiselEntity {
    name: string;
    isAwesome: boolean = !true;
}

Expected behavior is either that the default value is false, or that chisel apply returns an error.

honzasp avatar Jul 27 '22 12:07 honzasp

Note that if I try to do something similar with strings:

    nickname: string = "bo" + "b";

then I get an error from chisel apply: error: expression not supported. Same error should perhaps be reported in this case.

honzasp avatar Jul 27 '22 12:07 honzasp

After the fix in #1600 this code will be accepted. However, we handle expressions differently than we handle literals, and those examples could be literals, but will end up being treated as expressions.

Leaving it open for a bit longer until we can treat them as the literals that they are.

glommer avatar Aug 02 '22 11:08 glommer

Hmm, so what is the difference between a literal and expression default value? It might be confusing if isAwesome: boolean = false behaves differently from isAwesome: boolean = !true.

honzasp avatar Aug 04 '22 09:08 honzasp

it is confusing, which is why I am leaving this issue open and not closing with the other fix =p

The difference is that for literals, we can make the property hot-addable and/or removable.

glommer avatar Aug 04 '22 12:08 glommer