Skip to content

compile time echo steals newline from stderr so it's included in stdout instead #16334

@RSDuck

Description

@RSDuck

Example

Say we have this program saved as test.nim

static:
    echo "test"

proc abc(x: float) =
    discard
proc abc(x: int) =
    discard

abc("test")

And we inspect stdout and stderr using this program (if you're a command line wiz you could probably do that simpler):

import osproc, streams

let process = startProcess("nim", args = ["check", "test.nim"], options = {poUsePath})
discard process.waitForExit()

echo "std out:"
echo process.outputStream().readAll()
echo "std err:"
echo process.errorStream().readAll()

Current Output

std out:

test

std err:
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: used config file 'C:\Nim\config\config.nims' [Conf]
.....C:\Users\Kemal\Desktop\neuerordner\test.nim(22, 4) Error: type mismatch: got <string>
but expected one of:
proc abc(x: float)
  first type mismatch at position: 1
  required type for x: float
  but expression '"test"' is of type: string
proc abc(x: int)
  first type mismatch at position: 1
  required type for x: int
  but expression '"test"' is of type: string

expression: abc("test")
C:\Users\Kemal\Desktop\neuerordner\test.nim(5, 6) Hint: 'y' is declared but not used [XDeclaredButNotUsed]
C:\Users\Kemal\Desktop\neuerordner\test.nim(19, 6) Hint: 'abc' is declared but not used [XDeclaredButNotUsed]
C:\Users\Kemal\Desktop\neuerordner\test.nim(17, 6) Hint: 'abc' is declared but not used [XDeclaredButNotUsed]
C:\Users\Kemal\Desktop\neuerordner\test.nim(1, 8) Warning: imported and not used: 'macros' [UnusedImport]

there's no newline between the dots and the path. But an additional one in stdout.

If the echo is removed this is the output:

std out:

std err:
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: used config file 'C:\Nim\config\config.nims' [Conf]
.....
C:\Users\Kemal\Desktop\neuerordner\test.nim(20, 4) Error: type mismatch: got <string>
but expected one of:
proc abc(x: float)
  first type mismatch at position: 1
  required type for x: float
  but expression '"test"' is of type: string
proc abc(x: int)
  first type mismatch at position: 1
  required type for x: int
  but expression '"test"' is of type: string

expression: abc("test")
C:\Users\Kemal\Desktop\neuerordner\test.nim(3, 6) Hint: 'y' is declared but not used [XDeclaredButNotUsed]
C:\Users\Kemal\Desktop\neuerordner\test.nim(17, 6) Hint: 'abc' is declared but not used [XDeclaredButNotUsed]
C:\Users\Kemal\Desktop\neuerordner\test.nim(15, 6) Hint: 'abc' is declared but not used [XDeclaredButNotUsed]
C:\Users\Kemal\Desktop\neuerordner\test.nim(1, 8) Warning: imported and not used: 'macros' [UnusedImport]

Additional Information

nim -v
Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2020-12-12
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: d15f63a0f2d431a516601530196ac01c26e00f53
active boot switches: -d:release

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