argparse icon indicating copy to clipboard operation
argparse copied to clipboard

A lazy string crashes the compiler

Open SirNickolas opened this issue 2 years ago • 4 comments

An example from the Readme, reduced:

import argparse;

struct T {
    @(PositionalArgument(0).Description(() => "Argument description"))
    string param0;
}

void main() {
    CLI!T.parseArgs!((T t) { })(["-h"]); // SIGILL
}

DMD 2.105.3.

SirNickolas avatar Nov 18 '23 06:11 SirNickolas

I reproduced this issue. Will run dustmite to minimize test case.

andrey-zherikov avatar Dec 21 '23 20:12 andrey-zherikov

Reduced test case:

void main() {
    CLI; // SIGILL
}

template CLI()
{
    static parseKnownArgs()
    {
		callParser!(Config.init)();
    }
}

struct Config
{
    enum StylingMode { autodetect}
    StylingMode stylingMode ;
}

auto enableStyling(Config config)(bool enable)
{
    Config c ;
    c.stylingMode = enable ? Config.StylingMode: Config.StylingMode;
    return c;
}

bool callParser(Config config)()
{
	callParser!(enableStyling!(Config.init)(false));
}

Crashes with:

$ /usr/bin/dmd source.reduced/app.d
source.reduced/app.d(22): Error: CTFE internal error: literal `StylingMode`
Illegal instruction

I'll try to split callParser functions into two.

andrey-zherikov avatar Dec 21 '23 21:12 andrey-zherikov

c.stylingMode = enable ? Config.StylingMode: Config.StylingMode;

But Config.StylingMode is a type, not a value. Dustmite made a mistake in the process and reduced to it, not the actual bug we’re hunting.

SirNickolas avatar Dec 21 '23 21:12 SirNickolas

c.stylingMode = enable ? Config.StylingMode: Config.StylingMode;

But Config.StylingMode is a type, not a value. Dustmite made a mistake in the process and reduced to it, not the actual bug we’re hunting.

This looks similar to https://issues.dlang.org/show_bug.cgi?id=24246

Any idea how to proceed with this issue while ICE is not fixed?

andrey-zherikov avatar Dec 22 '23 18:12 andrey-zherikov