nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.58k stars 1.47k forks source link

The hint `ConvFromXtoItselfNotNeeded:on` does not show the file or the line that caused it #21759

Closed noahehall closed 1 year ago

noahehall commented 1 year ago

Description

setting this in config.nims

switch("hintAsError", "ConvFromXtoItselfNotNeeded:on")

does not reveal the file or line with error

going through each file one by one, i found the error.

import std/[strformat, oserrors]

when defined(linux):
  echo fmt"{osErrorMsg OSErrorCode osLastError()=}"

Nim Version

[ updated to latest choosenim #devel] $ nim --v Nim Compiler Version 1.9.3 [Linux: amd64] Compiled at 2023-05-01 Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Current Output

# log from vscode code runner extension
[Running] echo bookofnim.nim | grep -e 'nims$' && nim e "/home/poop/git/foss/bookofnim/src/"bookofnim.nim || nim r --verbosity:0 "/home/poop/git/foss/bookofnim/src/"bookofnim.nim
this at compile time
(1, 24) Error: conversion from OSErrorCode to itself is pointless [ConvFromXtoItselfNotNeeded]

[Done] exited with code=1 in 1.193 seconds

Expected Output

it should include the file and line number

Possible Solution

go through each file one by one ;)~

Additional Information

[update]

the same thing occurs for TimeoutError


import std/[httpclient, json, strformat]

const
  timeout = 1
  endpoint = "https://postman-echo.com/"
  postme = endpoint & "post"
let
  data = %*{"data": { "user": "resu", "pass": "ssap"}}

let fetch = newHttpClient(timeout = timeout)
fetch.headers = newHttpHeaders({ "Content-Type": "application/json" })
echo fmt"{fetch.postContent postme, body = $data=}"


Error: unhandled exception: Call to 'readLine' timed out. [TimeoutError]
Error: execution of an external program failed: '/home/poop/.cache/nim/servers_r/servers_7938C9FA9E19EB2FB2FF0432C7445052F32F0A70'
``
metagn commented 1 year ago

Nothing specific to the hint, fmt just does not propagate line information

import std/strformat

echo fmt"{string ""abc""}"
lib/core/macros.nim(533, 8) Hint: conversion from string to itself is pointless [ConvFromXtoItselfNotNeeded]

Which is kind of expected that it doesn't extract the exact location inside a string literal, but it could at least give the location of the full string literal

(After looking a little bit, fmt has entirely static parameters, so it's a bit hard to extract line information)