Skip to content

vscode dscanner - struct initializer with named argument confuses DScanner #966

Open

Description

@tknawara

Hi,

I've been using D in vscode with code-d extension, now I have an assoc array that I'm trying to initialize where the values are a struct.

Using named arguments in the struct shows so many errors in vscode, (and formatting also seems to be confused) while dmd compiles the code just fine, this is a screenshot.

Image

and full code snippet

struct OperandConstraint
{
    OperandKind[] allowedKind;
}

struct InstructionSemaInfo
{
    size_t operandCount;
    bool allowMemoryToMemory;
    bool allowImmAsOperand;
    bool srcMustBeMemory;
    OperandConstraint[] operandConstraints;
    string[] notes;
}

InstructionSemaInfo info = {operandCount: 2};

immutable InstructionSemaInfo[Mnemonic] instructionSemaTable = [
    Mnemonic.mov: InstructionSemaInfo(
    operandCount : 2,
    allowMemoryToMemory:
        false,
    allowImmAsOperand:
        true,
    srcMustBeMemory:
        false,
    operandConstraints:
        [
            OperandConstraint([OperandKind.register, OperandKind.memory]),
            OperandConstraint([
                    OperandKind.register, OperandKind.memory, OperandKind.imm
                ]),
        ],
    notes:
        []
    ),
];

Compiling this with dmd just works

Image

Activity

  1. KaruroChori commented on Jun 24, 2025

    @KaruroChori

    As for my tests, the current version of d-scanner works well with named args. I think it is a downstream problem with the vscode extension.

    For reference, emitting the AST of

    module error;
    
    struct Type{
        int x;
    }
    
    int main(){
        Type(x:5);
    }

    results in no syntax error, even if the scanner used by the extension will complain:

    <?xml version="1.0"?>
    <module>
    <moduleDeclaration>
    <identifierChain>
    <identifier>error</identifier>
    </identifierChain>
    </moduleDeclaration>
    <declaration>
    <structDeclaration line="3">
    <name>Type</name><structBody>
    <declaration>
    <variableDeclaration>
    <type pretty="int">
    <type2>int</type2>
    </type>
    <declarator line="4">
    <name>x</name></declarator>
    </variableDeclaration>
    </declaration>
    </structBody>
    </structDeclaration>
    </declaration>
    <declaration>
    <functionDeclaration line="7">
    <name>main</name><type pretty="int">
    <type2>int</type2>
    </type>
    <parameters>
    </parameters>
    <functionBody>
    <blockStatement>
    <declarationsAndStatements>
    <declarationOrStatement>
    <statement>
    <statementNoCaseNoDefault>
    <expressionStatement>
    <expression>
    <unaryExpression>
    <functionCallExpression>
    <unaryExpression>
    <primaryExpression>
    <identifierOrTemplateInstance>
    <identifier>Type</identifier>
    </identifierOrTemplateInstance>
    </primaryExpression>
    </unaryExpression>
    <arguments>
    <argumentList>
    <argument named="x">
    <unaryExpression>
    <primaryExpression>
    <intLiteral>5</intLiteral>
    </primaryExpression>
    </unaryExpression>
    </argument>
    </argumentList>
    </arguments>
    </functionCallExpression>
    </unaryExpression>
    </expression>
    </expressionStatement>
    </statementNoCaseNoDefault>
    </statement>
    </declarationOrStatement>
    </declarationsAndStatements>
    </blockStatement>
    </functionBody>
    </functionDeclaration>
    </declaration>
    </module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions