jamesjuett / lobster

Interactive Program Visualization Tools
8 stars 3 forks source link

Out-of-line definition of non-declared member function should yield error #304

Open jamesjuett opened 2 years ago

jamesjuett commented 2 years ago

image

iteemhe commented 2 years ago

This issue is caused by declarations.createFunctionDeclarationFromDefinitionAST.

    // if the declarator has a qualified name, we need to check to see if a previous
    // declaration for the function already exists, and if so, use that one
    if (declarator.name && isQualifiedName(declarator.name)) {
        let prevEntity = context.program.getLinkedFunctionEntity(declarator.name);
        if (prevEntity) {
            return prevEntity.firstDeclaration;
        }
    }

I do not understand this chunk of code. Basically, when we define A::A(string c), this function will not be created by createFunctionDeclarationFromDefinitionAST method. Because this method will lookup the already defined function with the same name. In this case, it will find the default constructor in class A {};. So, the later invalid declaration does not exist at all.

Screen Shot 2022-03-01 at 14 26 45