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

Compliation error when formatting a complex number #24666

Closed
lscrd opened this issue Feb 4, 2025 · 2 comments · Fixed by #24667
Closed

Compliation error when formatting a complex number #24666

lscrd opened this issue Feb 4, 2025 · 2 comments · Fixed by #24667

Comments

@lscrd
Copy link

lscrd commented Feb 4, 2025

Description

The following code doesn’t compile:

import std/[complex, strformat]

let z = complex64(1, 2)
echo fmt"{z}"

The error occurs in procedure "formatValueAsComplexNumber". The procedure "contains" with expected signature is not available.

Nim Version

Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1
active boot switches: -d:release

Also encountered with development version.

Current Output

Compilation error:

/tmp/x.nim(4, 9) template/generic instantiation of `fmt` from here
/home/xxx/.choosenim/toolchains/nim-2.2.0/lib/pure/complex.nim(469, 31) template/generic instantiation of `formatValueAsComplexNumber` from here
/home/xxx/.choosenim/toolchains/nim-2.2.0/lib/pure/complex.nim(449, 31) Error: type mismatch
Expression: contains(specifier, {'e', 'E', 'f', 'F', 'g', 'G'})
  [1] specifier: string
  [2] {'e', 'E', 'f', 'F', 'g', 'G'}: set[char]

Expected one of (first mismatch at [position]):
[1] func contains[T](x: set[T]; y: T): bool
[1] proc contains[U, V, W](s: HSlice[U, V]; value: W): bool
[2] proc contains[T](a: openArray[T]; item: T): bool

Expected Output

No compilation error.

Known Workarounds

A workaround consists to add "strutils" to the list of imported modules.

This compiles without error:

import std/[complex, strformat, strutils]

let z = complex64(1, 2)
echo fmt"{z}"

Additional Information

In module "complex.nim" of the standard library, the procedure "contains" with the expected signature is not available. It can be found in "std/strutils". Importing "strutils" (or at least the procedure "contains") in "complex.nim" would solve the problem but would create a dependency.

@metagn
Copy link
Collaborator

metagn commented Feb 5, 2025

!nim c

import std/[complex, strformat]

let z = complex64(1, 2)
discard fmt"{z}"

Copy link
Contributor

github-actions bot commented Feb 5, 2025

🐧 Linux bisect by @metagn (collaborator)
devel 👎 FAIL

Output


Filesize 0 (0 bytes)
Duration

stable 👎 FAIL

Output


Filesize 0 (0 bytes)
Duration

2.0.10 👍 OK

Output


Filesize 108.70 Kb (111,304 bytes)
Duration

2.0.0 👍 OK

Output


Filesize 118.96 Kb (121,816 bytes)
Duration

1.6.20 👍 OK

Output


Filesize 122.80 Kb (125,752 bytes)
Duration

1.4.8 👍 OK

Output


Filesize 119.48 Kb (122,352 bytes)
Duration

1.2.18 👍 OK

Output


Filesize 119.53 Kb (122,400 bytes)
Duration

1.0.10 👍 OK

Output


Filesize 114.60 Kb (117,352 bytes)
Duration

#52784f32b ➡️ 🐛

Diagnostics

angel ezquerra introduced a bug at 2023-11-10 05:29:55 +0100 on commit #52784f32b with message:


The bug is in the files:


The bug can be in the commits:

(Diagnostics sometimes off-by-one).

Stats
  • GCC 13.3.0
  • Clang 18.1.3
  • NodeJS 18.2
  • Created 2025-02-05T00:35:16Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 38 mins bisecting 1166 commits at 30 commits per second

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

Successfully merging a pull request may close this issue.

3 participants