Open Ntsekees opened 1 year ago
!nim c
func f(s: string): string {.compileTime.}
const FCT = f("abcd")
doAssert FCT == "abcd", FCT
func f(s: string): string {.compileTime.} = s
@juancarlospaco (contributor)devel :-1: FAIL
Output
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim temp
/home/runner/.choosenim/toolchains/nim-#devel/lib/std/assertions.nim failedAssertImpl
/home/runner/.choosenim/toolchains/nim-#devel/lib/std/assertions.nim raiseAssert
/home/runner/.choosenim/toolchains/nim-#devel/lib/system/fatal.nim sysFatal
Error: unhandled exception: /home/runner/work/Nim/Nim/temp.nim(3, 1) `FCT == "abcd"` [AssertionDefect]
Error: execution of an external program failed: '/home/runner/work/Nim/Nim/temp'
2023-07-09T14:32:39Z
2023-07-09T14:33:17
2023-07-09T14:33:19
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim temp
/home/runner/.choosenim/toolchains/nim-1.6.14/lib/system/assertions.nim failedAssertImpl
/home/runner/.choosenim/toolchains/nim-1.6.14/lib/system/assertions.nim raiseAssert
/home/runner/.choosenim/toolchains/nim-1.6.14/lib/system/fatal.nim sysFatal
Error: unhandled exception: /home/runner/work/Nim/Nim/temp.nim(3, 10) `FCT == "abcd"` [AssertionDefect]
Error: execution of an external program failed: '/home/runner/work/Nim/Nim/temp '
2023-07-09T14:32:39Z
2023-07-09T14:33:19
2023-07-09T14:33:20
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim temp
/home/runner/.choosenim/toolchains/nim-1.6.0/lib/system/assertions.nim failedAssertImpl
/home/runner/.choosenim/toolchains/nim-1.6.0/lib/system/assertions.nim raiseAssert
/home/runner/.choosenim/toolchains/nim-1.6.0/lib/system/fatal.nim sysFatal
Error: unhandled exception: /home/runner/work/Nim/Nim/temp.nim(3, 10) `FCT == "abcd"` [AssertionDefect]
Error: execution of an external program failed: '/home/runner/work/Nim/Nim/temp '
2023-07-09T14:32:39Z
2023-07-09T14:33:24
2023-07-09T14:33:25
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim temp
/home/runner/.choosenim/toolchains/nim-1.4.0/lib/system/assertions.nim failedAssertImpl
/home/runner/.choosenim/toolchains/nim-1.4.0/lib/system/assertions.nim raiseAssert
/home/runner/.choosenim/toolchains/nim-1.4.0/lib/system/fatal.nim sysFatal
Error: unhandled exception: /home/runner/work/Nim/Nim/temp.nim(3, 10) `FCT == "abcd"` [AssertionDefect]
Error: execution of an external program failed: '/home/runner/work/Nim/Nim/temp '
2023-07-09T14:32:39Z
2023-07-09T14:33:29
2023-07-09T14:33:30
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim temp
/home/runner/.choosenim/toolchains/nim-1.2.0/lib/system/assertions.nim failedAssertImpl
/home/runner/.choosenim/toolchains/nim-1.2.0/lib/system/assertions.nim raiseAssert
/home/runner/.choosenim/toolchains/nim-1.2.0/lib/system/fatal.nim sysFatal
Error: unhandled exception: /home/runner/work/Nim/Nim/temp.nim(3, 10) `FCT == "abcd"` [AssertionError]
Error: execution of an external program failed: '/home/runner/work/Nim/Nim/temp '
2023-07-09T14:32:39Z
2023-07-09T14:33:46
2023-07-09T14:33:47
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim temp
/home/runner/.choosenim/toolchains/nim-1.0.0/lib/system/assertions.nim failedAssertImpl
/home/runner/.choosenim/toolchains/nim-1.0.0/lib/system/assertions.nim raiseAssert
/home/runner/.choosenim/toolchains/nim-1.0.0/lib/system/fatal.nim sysFatal
Error: unhandled exception: /home/runner/work/Nim/Nim/temp.nim(3, 10) `FCT == "abcd"` [AssertionError]
Error: execution of an external program failed: '/home/runner/work/Nim/Nim/temp '
2023-07-09T14:32:39Z
2023-07-09T14:34:01
2023-07-09T14:34:02
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
49 minutes
bisecting 6
commits at 0
commits per second.
Description
{.compileTime.}
on a function with forward declaration, called before the function's body is defined, causes the function to silently fail, returning an empty string. (Nim compiler v1.6.10 [Linux: amd64].) The demonstration code below should suffice for depicting the issue:In this code, we define 4 dummy functions: • two of them are tagged with the
{.compileTime.}
pragma, the two others aren't (and run at runtime). • two of them are forward declared (with their body defined below the call site), the two others are fully defined above their call site.Constatations: Of the four functions, the two that are defined (body included) above the call site work seamlessly. The forward-declared runtime function doesn't work with the
const
keyword, but that may be intentional (let
works however). The forward-declared function tagged with{.compileTime.}
fails and return an empty string, instead of the expectedabcd
string, which all the three other functions return.It seems that the compiler fails to fetch (or otherwise execute properly) the body of that compileTime function; it is odd that it doesn't cause a crash or an error and that an actual dummy value (an empty string) is returned, letting the program run successfully.
Nim Version
Nim Compiler Version 1.6.10 [Linux: amd64] Compiled at 2022-11-21 Copyright (c) 2006-2021 by Andreas Rumpf
git hash: f1519259f85cbdf2d5ff617c6a5534fcd2ff6942 active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
I have only tested the test code on a single version of Nim, and on a single OS/architecture.