Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RSDuck opened this issue Dec 12, 2020 · 1 comment
Closed

Comments

@RSDuck
Copy link
Contributor

RSDuck commented Dec 12, 2020

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
RSDuck added a commit to RSDuck/Nim that referenced this issue Dec 12, 2020
RSDuck added a commit to RSDuck/Nim that referenced this issue Dec 12, 2020
@timotheecour
Copy link
Member

timotheecour commented Dec 12, 2020

when true:
  when defined case2a:
    static: echo "test"
    nonexistant
  else:
    import os, osproc, streams
    let process = startProcess(getCurrentCompilerExe(), args = ["check", "-f", "-d:case2a", currentSourcePath], options = {poUsePath})
    discard process.waitForExit()
    echo "std out:"
    echo process.outputStream().readAll()
    echo "std err:"
    echo process.errorStream().readAll()

prints:

XDG_CONFIG_HOME= nim r -d:case2 -f --hints:off $timn_D/tests/nim/all/t11495.nim
std out:

test

std err:
Hint: used config file '/Users/timothee/git_clone/nim/Nim_devel/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/Nim_devel/config/config.nims' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/config.nims' [Conf]
..../Users/timothee/git_clone/nim/timn/tests/nim/all/t11495.nim(39, 5) Error: undeclared identifier: 'nonexistant'

  • CC hints should go to stderr, not stdout (like other hints)

@Araq Araq closed this as completed in b6443c9 Dec 14, 2020
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
* fix nim-lang#16334

* rename isstdout -> isStdout

* separate lastMsgWasDot for stdout and stderr

* simplify logic
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
* fix nim-lang#16334

* rename isstdout -> isStdout

* separate lastMsgWasDot for stdout and stderr

* simplify logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants