andrey-zherikov / argparse

Parser for command-line arguments
https://andrey-zherikov.github.io/argparse/
Boost Software License 1.0
30 stars 6 forks source link

Replace @SubCommands SumType!(TYPES...) with SubCommand!(TYPES...) #143

Closed andrey-zherikov closed 7 months ago

andrey-zherikov commented 8 months ago

Closes #80

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (3d1e8b2) 99.22% compared to head (e5bb105) 99.23%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #143 +/- ## ======================================= Coverage 99.22% 99.23% ======================================= Files 27 28 +1 Lines 1943 1966 +23 ======================================= + Hits 1928 1951 +23 Misses 15 15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

SirNickolas commented 8 months ago
struct A
{
    int[] arr;
}

immutable one = SubCommand!A(A([1]));
SubCommand!A mut;
mut = one;
mut.match!(_ => _.arr[0] = 2);
assert(one.match!(_ => _.arr[0]) == 2); // Successfully modified an immutable object!

Still have to investigate if it’s a SubCommand’s fault or SumType’s.

andrey-zherikov commented 8 months ago

Still have to investigate if it’s a SubCommand’s fault or SumType’s

It seems also related to int[] array - this fails as expected:

struct A
{
    int arr;
}

immutable one = SubCommand!A(A(1));

SubCommand!A mut = one;
mut = one;
mut.match!(_ => _.arr = 2);

assert(one.match!(_ => _.arr) == 2);
andrey-zherikov commented 8 months ago
struct None {}

struct S(T)
{
    SumType!(None,T) a;
}

struct A
{
    int[] arr;
}

immutable one = S!A.init;
immutable two = SumType!(None,A)(A([1]));
immutable three = SumType!(A,None)(A([1]));
immutable four = SumType!(A)(A([1]));

one and two do compile and three and four do not (cannot implicitly convert expression)

andrey-zherikov commented 8 months ago

Asked question on forum.

andrey-zherikov commented 8 months ago

May be adding None to SumType was not good solution so I'd like to re-think my proposal a bit:

andrey-zherikov commented 8 months ago

Pushed changes and confirmed that this does not compile:

    struct A
    {
        int[] i;
    }

    immutable sub = SubCommand!(A)(A([1]));

Error:

Error: cannot implicitly convert expression SubCommand(Nullable(DontCallDestructorT(SumType(Storage(A(null)), cast(ubyte)0u)), true)).this(A([1])) of type SubCommand!(A) to immutable(SubCommand!(A))

andrey-zherikov commented 8 months ago

@SirNickolas Is this now good from your point of view?