Skip to content

Option "--lineDir:on" may mess up code in emit pragma #6345

Open
@MednauN

Description

@MednauN

Nim version 0.17.2 (from commit 811fbda)

That's quite unusual issue, but I caught it today in our project.
Here's the sample code:

proc f(): int32 =
  {.emit: """
    #if 1
    `result` = 1;
    #endif
  """.}

echo f()

The important part here is that code inside emit begins with a C preprocessor directive. If you compile this code with command
nim c --lineDir:on test.nim
compiler produces following C code:

N_NIMCALL(NI32, f_nihCtddZTotXPkpuYzTLdQ)(void) {
	NI32 result;	nimfr_("f", "test.nim");	result = (NI32)0;
#line 3 "C:\\projects\\temp\\test.nim"
	nimln_(3, "test.nim");	    #if 1
    result = 1;
    #endif
  
	popFrame();	return result;}

As you can see, first line break before #if 1 is somehow removed and #if 1 goes to the same line as nimln_. Well, and this code doesn't compile since preprocessor directives should start with a new line.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions