Skip to content

compile: a nested /* */ inside a doxygen header truncates the header and emits code as SAS #1499

Closed

Description

@sasjs-dev

The compiler strips comments using everything between /** and the first */, so a doxygen header containing a block comment of its own is truncated at that inner */. The remainder of the header - including any code in a usage example - is emitted as live SAS, and the file then fails somewhere else entirely with a misleading error.

Reproduction

A macro whose header has a nested comment in its usage section:

/**
  @file
  @brief Example
  @details Usage:

      %my_macro(outlib=web1)
      /* reaching here means the child completed */
      data _null_;
        set work.status;
      run;

  @param [in] outlib Output libref

**/

%macro my_macro(outlib=0);
  %put outlib=&outlib;
%mend my_macro;

After sasjs compile the compiled program starts mid-header:

      data _null_;
        set work.status;
      run;

  @param [in] outlib Output libref

**/

%macro my_macro(outlib=0);

/**, @file, @brief and the start of the usage block are gone, and that data _null_ step executes for real.

What it cost

The run failed several hundred lines later with ERROR: No matching %MACRO statement for this %MEND statement. - the truncated header text had disturbed the code following it - so the error named nothing near the cause. It took a bisect of the macro file to find that a comment was responsible.

Expected

Match the closing **/ rather than the first */ when stripping a doxygen block, or fail with a clear message when a header contains a nested block comment.

Suggestion

A @sasjs/lint rule flagging /* inside a doxygen header would catch this at author time, since compile-time detection is far from the author's edit. Happy to raise that separately if you would rather keep the two apart.

Activity

  1. added
    bug
    on Oct 26, 2026
  2. sasjs-dev commented on Oct 27, 2026

    @sasjs-dev
    ContributorAuthor

    Compile-time fix raised in sasjs/utils#288.

    removeHeader strips to the first close marker, which is exactly where the SAS lexer ends the comment - so the compiled output was faithful to SAS, and the defect was that nothing said so. The header is now validated before stripping, and the error names the file, the line that closed the header, the line that opened the nested comment, and the lines that would run as SAS:

    src/services/nested.sas: the doxygen header is closed at line 7, before its **/ terminator at line 11: the close marker on line 7 belongs to the block comment opened at line 6. SAS block comments do not nest, so lines 8-11 - including the header's closing **/ - would be compiled as SAS. Remove the block comment from the header, or move it below the header.
    

    It is wired in removeHeader (macro leaves) and loadDependenciesFile (services, jobs, tests, files), so both the CLI and the server compile paths fail at the header rather than at deploy.

    Not doing the alternative of matching **/ instead of the first close marker: that makes the compile pass on a file SAS still rejects, so the failure moves to run time with the same misleading error. Every doxygen header in core, cli and utils (636 of them) closes with **/ alone on its line and none contains a nested /*, so the check has no false positives on the corpus.

    The @sasjs/lint rule from the suggestion is complementary and belongs in that repo - lint never sees dependency macros pulled from another project. Worth raising separately.

  3. sasjs-dev commented on Oct 27, 2026

    @sasjs-dev
    ContributorAuthor

    Released across the three packages:

    Verified in the published tarball rather than only in git: @sasjs/[email protected]'s build/commands/compile/internal/loadDependencies.js passes filePath to removeHeader, build/commands/build/build.js does the same for the service member path, and the manifest resolves @sasjs/utils ^4.1.1 with @sasjs/lint ^4.4.0 as a peer.

    Both lint rules default to WARNING, so upgrading does not change a project's lint return code; set "severityLevel": {"noNestedCommentsInHeader": "error"} to make it fatal. Closing.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions