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 error on questionable library with version-1-6 branch #22897

Open
elcritch opened this issue Oct 31, 2023 · 10 comments
Open

Compile error on questionable library with version-1-6 branch #22897

elcritch opened this issue Oct 31, 2023 · 10 comments

Comments

@elcritch
Copy link
Contributor

elcritch commented Oct 31, 2023

Description

Testing out release 1.6.16 (or version-1-6) causes compilation failures for questionable. The library does has a macro =? that that creates a new variable, but now there's a compilation failure saying the variable cannot be found. This only seems to occur when calling the =? macro inside a generic proc. Note that adding expandMacro fixes the first compilation failure but fails on the next.

Nim Version

Nim Compiler Version 1.6.16 [MacOSX: arm64]
Compiled at 2023-10-10
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 3c9b68d
active boot switches: -d:release -d:danger

Current Output

## Failure 1

┌─(~/projs/status/nim-codex-v2/vendor/questionable)─────────────────────(jaremycreechley@Jaremys-MBP-2:s024)─┐
└─(15:33:51 on main ✹ ✭)──> nimble test                                                    1 ↵ ──(Tue,Oct31)─┘
   Warning: Using the environment variable: NIMBLE_DIR='/Users/jaremycreechley/.nimble'
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/questionable.nimble
   Warning: Using project local deps mode
  Verifying dependencies for test@0.1.0
  asdf-nim: regenerated shims

   Warning: Using project local deps mode
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nimble
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.16/config/nim.cfg' [Conf]
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.16/config/config.nims' [Conf]
Hint: used config file '/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/config.nims' [Conf]
....................................................................................................................
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(9, 7) template/generic instantiation of `suite` from here
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(120, 8) template/generic instantiation of `test` from here
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(124, 12) Error: undeclared identifier: 'value'
stack trace: (most recent call last)
/private/var/folders/yp/ky1yl8tn1fjclx29ftm_68th0000gn/T/nimblecache-1505406134/nimscriptapi_909577865.nim(187, 16)
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nimble(11, 8) testTask
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) exec
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nim c -f -r --skipParentCfg --warningAsError[UnsafeDefault]:on --warningAsError[ProveInit]:on test.nim [OSError]
     Error: Exception raised during nimble script execution
stack trace: (most recent call last)
/private/var/folders/yp/ky1yl8tn1fjclx29ftm_68th0000gn/T/nimblecache-1505406134/nimscriptapi_909577865.nim(187, 16)
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/questionable.nimble(11, 12) testTask
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) exec
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nimble test -y [OSError]
     Error: Exception raised during nimble script execution

## Failure 2
└─(15:42:06 on main ✹ ✭)──> nimble test                                                    1 ↵ ──(Tue,Oct31)─┘
   Warning: Using the environment variable: NIMBLE_DIR='/Users/jaremycreechley/.nimble'
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/questionable.nimble
   Warning: Using project local deps mode
  Verifying dependencies for test@0.1.0
  asdf-nim: regenerated shims

   Warning: Using project local deps mode
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nimble
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.16/config/nim.cfg' [Conf]
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.16/config/config.nims' [Conf]
Hint: used config file '/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/config.nims' [Conf]
....................................................................................................................
if (
  let evaluated`gensym706 = option
  let option`gensym706 = option(evaluated`gensym706)
  type
    T`gensym706 = typeof(option`gensym706.unsafeGet())
  let value = if isSome(option`gensym706): unsafeGet(option`gensym706) else:
    placeholder(T`gensym706)
  isSome(option`gensym706)): $value
else:
  "none"
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(9, 7) template/generic instantiation of `suite` from here
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(131, 8) template/generic instantiation of `test` from here
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(141, 11) template/generic instantiation of `check` from here
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/pure/unittest.nim(681, 43) template/generic instantiation of `toString` from here
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(136, 18) template/generic instantiation of `bindLet` from here
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim(132, 9) Error: inconsistent typing for reintroduced symbol 'value': previous type was: string; new type is: int
stack trace: (most recent call last)
/private/var/folders/yp/ky1yl8tn1fjclx29ftm_68th0000gn/T/nimblecache-1505406134/nimscriptapi_909577865.nim(187, 16)
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nimble(11, 8) testTask
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) exec
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nim c -f -r --skipParentCfg --warningAsError[UnsafeDefault]:on --warningAsError[ProveInit]:on test.nim [OSError]
     Error: Exception raised during nimble script execution
stack trace: (most recent call last)
/private/var/folders/yp/ky1yl8tn1fjclx29ftm_68th0000gn/T/nimblecache-1505406134/nimscriptapi_909577865.nim(187, 16)
/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/questionable.nimble(11, 12) testTask
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) exec
/Users/jaremycreechley/.asdf/installs/nim/1.6.16/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nimble test -y [OSError]
     Error: Exception raised during nimble script execution

Expected Output

   Warning: Using the environment variable: NIMBLE_DIR='/Users/jaremycreechley/.nimble'
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/questionable.nimble
   Warning: Using project local deps mode
  Verifying dependencies for test@0.1.0
  asdf-nim: regenerated shims

   Warning: Using project local deps mode
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nimble
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.14/config/nim.cfg' [Conf]
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.14/config/config.nims' [Conf]
Hint: used config file '/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/config.nims' [Conf]
....................................................................................................................
if (
  let evaluated`gensym703 = option
  let option`gensym703 = option(evaluated`gensym703)
  type
    T`gensym703 = typeof(option`gensym703.unsafeGet())
  let value = if isSome(option`gensym703): unsafeGet(option`gensym703) else:
    placeholder(T`gensym703)
  isSome(option`gensym703)): $value
else:
  "none"
if (
  let evaluated`gensym719 = option
  let option`gensym719 = option(evaluated`gensym719)
  type
    T`gensym719 = typeof(option`gensym719.unsafeGet())
  let value = if isSome(option`gensym719): unsafeGet(option`gensym719) else:
    placeholder(T`gensym719)
  isSome(option`gensym719)): $value
else:
  "none"
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/std/private/digitsutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/assertions.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/formatfloat.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/dollars.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/io.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/std/exitprocs.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/parseutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/math.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/unicode.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/strutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/streams.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/options.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/posix/posix.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/times.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/hashes.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sets.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sequtils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/os.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/strformat.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/terminal.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/unittest.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/tables.nim
CC: ../../questionable/private/binderror.nim
CC: ../../questionable/binding.nim
CC: ../../questionable/options.nim
CC: test.nim
Hint:  [Link]
ld: warning: ignoring duplicate libraries: '-lm'
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
83349 lines; 1.688s; 146.102MiB peakmem; proj: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test.nim; out: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test [SuccessX]
Hint: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/options/test  [Exec]

[Suite] optionals
  [OK] ?Type is shorthand for Option[Type]
  [OK] ! gets value or raises Defect
  [OK] .? can be used for chaining optionals
  [OK] .? chain can be followed by . calls and operators
  [OK] .? chains work in generic code
  [OK] [] can be used for indexing optionals
  [OK] |? can be used to specify a fallback value
  [OK] =? can be used for optional binding
  [OK] =? can appear multiple times in conditional expression
  [OK] =? works with variable hiding
  [OK] =? works with var
  [OK] =? works with .?
  [OK] =? works in generic code
  [OK] =? works in generic code with variable hiding
  [OK] =? works with closures
  [OK] =? works with types that do not have a default value
  [OK] =? binds and unpacks tuples
  [OK] =? binds and unpacks tuples with named fields
  [OK] =? binds and unpacks tuples returned from proc
  [OK] =? binds and unpacks tuples returned from proc with unnamed fields
  [OK] =? binds and unpacks tuples with _
  [OK] =? binds and unpacks tuples with named fields
  [OK] =? binds variable to tuples with named fields
  [OK] =? binds to tuple types
  [OK] without statement can be used for early returns
  [OK] without statement evaluates optional expression only once
  [OK] .?[] can be used for indexing tables without raising KeyError
  [OK] .?[] can be used for indexing strings without raising IndexDefect
  [OK] .?[] can be used for indexing sequences without raising IndexDefect
  [OK] .?[] can be followed by calls, operators and indexing
  [OK] =? works with .?[]
  [OK] unary operator `-` works for options
  [OK] other unary operators work for options
  [OK] binary operator `+` works for options
  [OK] other binary operators work for options
  [OK] .? avoids wrapping option in option
  [OK] lifted operators avoid wrapping option in option
  [OK] .?[] avoids wrapping option in option
  [OK] .? chain evaluates optional expression only once
  [OK] =? evaluates optional expression only once
  [OK] |? evaluates optional expression only once
  [OK] .?[] evaluates optional expression only once
  [OK] lifted unary operators evaluate optional expression only once
  [OK] lifted binary operators evaluate optional expressions only once
  [OK] examples from readme work
   Warning: Using project local deps mode
  Verifying dependencies for test@0.1.0
      Info: Dependency on results@any version already satisfied
  Verifying dependencies for results@0.4.0
  asdf-nim: regenerated shims

   Warning: Using project local deps mode
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/results/test.nimble
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.14/config/nim.cfg' [Conf]
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.14/config/config.nims' [Conf]
Hint: used config file '/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/results/config.nims' [Conf]
............................................................................................................................
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/std/private/digitsutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/assertions.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/formatfloat.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/dollars.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/core/locks.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sharedlist.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/io.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/std/exitprocs.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/parseutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/math.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/unicode.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/strutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/streams.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/options.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/posix/posix.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/times.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/hashes.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sets.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sequtils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/os.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/strformat.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/terminal.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/unittest.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/concurrency/cpuinfo.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/concurrency/cpuload.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/concurrency/threadpool.nim
CC: nimbledeps/pkgs/results-0.4.0/results.nim
CC: ../../questionable/private/binderror.nim
CC: ../../questionable/binding.nim
CC: ../../questionable/results.nim
CC: test.nim
Hint:  [Link]
ld: warning: ignoring duplicate libraries: '-lm'
Hint: gc: refc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
84133 lines; 1.716s; 146.297MiB peakmem; proj: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/results/test.nim; out: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/results/test [SuccessX]
Hint: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/results/test  [Exec]

[Suite] result
  [OK] ?!Type is shorthand for Result[Type, ref CatchableError]
  [OK] conversion to string $ works for ?!Types
  [OK] ! gets value or raises Defect
  [OK] .? can be used for chaining results
  [OK] .? chain can be followed by . calls and operators
  [OK] .? chains work in generic code
  [OK] [] can be used for indexing results
  [OK] |? can be used to specify a fallback value
  [OK] =? can be used for optional binding
  [OK] =? can appear multiple times in conditional expression
  [OK] =? works with variable hiding
  [OK] =? works with var
  [OK] =? works with .?
  [OK] =? evaluates optional expression only once
  [OK] =? works in generic code
  [OK] =? works in generic code with variable hiding
  [OK] =? works with closures
  [OK] =? binds and unpacks tuples
  [OK] =? binds and unpacks tuples with named fields
  [OK] =? binds and unpacks tuples returned from proc
  [OK] =? binds and unpacks tuples returned from proc with unnamed fields
  [OK] =? binds and unpacks tuples with _
  [OK] =? binds and unpacks tuples with named fields
  [OK] =? binds variable to tuples with named fields
  [OK] =? binds to tuple types
  [OK] without statement works for results
  [OK] without statement can expose error
  [OK] without statement only exposes error variable inside block
  [OK] without statements with multiple bindings exposes first error
  [OK] without statement with error evaluates result only once
  [OK] without statement with error handles options as well
  [OK] without statement with error can be used more than once
  [OK] without statement with error works with deeply nested =? operators
  [OK] without statement with error works in generic code
  [OK] without statements with error can be nested
  [OK] without statement works in generic code using existing error name
  [OK] without statements with error work in nested calls
  [OK] without statement with error works in nested generic calls
  [OK] without statement with error works with multiple threads
  [OK] catch can be used to convert exceptions to results
  [OK] success can be called without argument
  [OK] failure can be called with string argument
  [OK] unary operator `-` works for results
  [OK] other unary operators work for results
  [OK] binary operator `+` works for results
  [OK] other binary operators work for results
  [OK] Result can be converted to Option
  [OK] Result error can be converted to Option
  [OK] failure can be used without type parameter in procs
  [OK] .? avoids wrapping result in result
  [OK] lifted operators avoid wrapping result in result
  [OK] .? chain evaluates result only once
  [OK] =? evaluates result only once
  [OK] |? evaluates result only once
  [OK] .?[] evaluates result only once
  [OK] lifted unary operators evaluate result only once
  [OK] lifted binary operators evaluate results only once
  [OK] conversion to option evaluates result only once
  [OK] conversion to error evaluates result only once
  [OK] examples from readme work

[Suite] result compatibility
  [OK] |?, =? and .option work on other types of Result
  [OK] =? works on other type of Result after without statement with error
   Warning: Using project local deps mode
  Verifying dependencies for test@0.1.0
      Info: Dependency on stew@any version already satisfied
  Verifying dependencies for stew@0.1.0
      Info: Dependency on results@any version already satisfied
  Verifying dependencies for results@0.4.0
      Info: Dependency on unittest2@any version already satisfied
  Verifying dependencies for unittest2@0.0.7
  asdf-nim: regenerated shims

   Warning: Using project local deps mode
  Executing task test in /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/stew/test.nimble
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.14/config/nim.cfg' [Conf]
Hint: used config file '/Users/jaremycreechley/.asdf/installs/nim/1.6.14/config/config.nims' [Conf]
Hint: used config file '/Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/stew/config.nims' [Conf]
.............................................................................................................................
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/std/private/digitsutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/assertions.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/formatfloat.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/dollars.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/core/locks.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sharedlist.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system/io.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/system.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/std/exitprocs.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/parseutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/math.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/unicode.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/strutils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/streams.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/options.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/posix/posix.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/times.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/hashes.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sets.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/collections/sequtils.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/os.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/strformat.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/terminal.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/unittest.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/concurrency/cpuinfo.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/concurrency/cpuload.nim
CC: ../../../../../../../.asdf/installs/nim/1.6.14/lib/pure/concurrency/threadpool.nim
CC: nimbledeps/pkgs/results-0.4.0/results.nim
CC: ../../questionable/private/binderror.nim
CC: ../../questionable/binding.nim
CC: ../../questionable/results.nim
CC: test.nim
Hint:  [Link]
ld: warning: ignoring duplicate libraries: '-lm'
Hint: gc: refc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
84135 lines; 1.686s; 146.391MiB peakmem; proj: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/stew/test.nim; out: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/stew/test [SuccessX]
Hint: /Users/jaremycreechley/projs/status/nim-codex-v2/vendor/questionable/testmodules/stew/test  [Exec]

[Suite] result
  [OK] ?!Type is shorthand for Result[Type, ref CatchableError]
  [OK] conversion to string $ works for ?!Types
  [OK] ! gets value or raises Defect
  [OK] .? can be used for chaining results
  [OK] .? chain can be followed by . calls and operators
  [OK] .? chains work in generic code
  [OK] [] can be used for indexing results
  [OK] |? can be used to specify a fallback value
  [OK] =? can be used for optional binding
  [OK] =? can appear multiple times in conditional expression
  [OK] =? works with variable hiding
  [OK] =? works with var
  [OK] =? works with .?
  [OK] =? evaluates optional expression only once
  [OK] =? works in generic code
  [OK] =? works in generic code with variable hiding
  [OK] =? works with closures
  [OK] =? binds and unpacks tuples
  [OK] =? binds and unpacks tuples with named fields
  [OK] =? binds and unpacks tuples returned from proc
  [OK] =? binds and unpacks tuples returned from proc with unnamed fields
  [OK] =? binds and unpacks tuples with _
  [OK] =? binds and unpacks tuples with named fields
  [OK] =? binds variable to tuples with named fields
  [OK] =? binds to tuple types
  [OK] without statement works for results
  [OK] without statement can expose error
  [OK] without statement only exposes error variable inside block
  [OK] without statements with multiple bindings exposes first error
  [OK] without statement with error evaluates result only once
  [OK] without statement with error handles options as well
  [OK] without statement with error can be used more than once
  [OK] without statement with error works with deeply nested =? operators
  [OK] without statement with error works in generic code
  [OK] without statements with error can be nested
  [OK] without statement works in generic code using existing error name
  [OK] without statements with error work in nested calls
  [OK] without statement with error works in nested generic calls
  [OK] without statement with error works with multiple threads
  [OK] catch can be used to convert exceptions to results
  [OK] success can be called without argument
  [OK] failure can be called with string argument
  [OK] unary operator `-` works for results
  [OK] other unary operators work for results
  [OK] binary operator `+` works for results
  [OK] other binary operators work for results
  [OK] Result can be converted to Option
  [OK] Result error can be converted to Option
  [OK] failure can be used without type parameter in procs
  [OK] .? avoids wrapping result in result
  [OK] lifted operators avoid wrapping result in result
  [OK] .? chain evaluates result only once
  [OK] =? evaluates result only once
  [OK] |? evaluates result only once
  [OK] .?[] evaluates result only once
  [OK] lifted unary operators evaluate result only once
  [OK] lifted binary operators evaluate results only once
  [OK] conversion to option evaluates result only once
  [OK] conversion to error evaluates result only once
  [OK] examples from readme work

[Suite] result compatibility
  [OK] |?, =? and .option work on other types of Result
  [OK] =? works on other type of Result after without statement with error

Possible Solution

No response

Additional Information

Adding this change to testmodules/options/test.nim to print out the expanded code:

  test "=? works in generic code":
    proc toString[T](option: ?T): string =
      expandMacros:
        if value =? option:
          $value
        else:
          "none"

Gives:

if (
  let evaluated`gensym706 = option
  let option`gensym706 = option(evaluated`gensym706)
  type
    T`gensym706 = typeof(option`gensym706.unsafeGet())
  let value = if isSome(option`gensym706): unsafeGet(option`gensym706) else:
    placeholder(T`gensym706)
  isSome(option`gensym706)): $value
else:
  "none"

The generated code looks fine. It also works properly in the previous test where the main different is the =? macro/template being called from a generic scope:

  test "=? works with .?":
    if a =? 42.some.?uint8:
      check a == 42.uint8
    else:
      fail
@elcritch
Copy link
Contributor Author

I'm trying to reduce this a bit. It's not 100% clear to me yet, but 1.6.16 may be exposing a previous bug in the library that was ignored before.

@ringabout
Copy link
Member

Indeed, it's a regression between 1.6.14 and 1.6.16. I think it's might be helpful to do bisect in order to find the cause.

@ringabout
Copy link
Member

Okay, I will do a bisect.

@ringabout
Copy link
Member

The bisect says b7a1210 might be the cause.

@SirOlaf
Copy link
Contributor

SirOlaf commented Nov 2, 2023

Weird issue with typed templates, previously it would still fail if one of the template arguments was typed, now it also fails when return is typed.

This example was broken in the past and is still broken

template tempA(x: int): untyped =
  let value {.inject.} = 2

proc procA[T](x: T) =
  tempA(x)
  echo value

This example seems to be newly broken

template tempA(x: untyped): int =
  let value {.inject.} = 2

proc procA[T](x: T) =
  tempA(x)
  echo value

Fully untyped templates expand immediately, once you introduce types it waits until generic instantiation, guess these checks happen before? I assume the core of the issue lies with this being required for overload resolution because you may try to pass a generic value to the template.
If that is the case, fix may be to handle injects similar to mixins and let the generic proc know to ignore them, could see this being problematic with when statements though + overload resolution will interfere.

This for example works

template tempA(x: int) =
  let value {.inject.} = 2

proc procA[T](x: T) =
  tempA(x)
  mixin value
  echo value

procA(2)

Simplest solution may be to simply mark generic procs that use templates as dirty, but that makes IDE tooling even worse. questionable is also still broken with that because then shadowing isn't done correctly anymore...

@SirOlaf
Copy link
Contributor

SirOlaf commented Nov 2, 2023

With this info it looks like a language design issue to me, pinging @Araq

@Araq
Copy link
Member

Araq commented Nov 2, 2023

template tempA(x: untyped): int =
  let value {.inject.} = 2

is not valid code as it does not produce an int.

@elcritch
Copy link
Contributor Author

elcritch commented Nov 2, 2023

Yah, I think the more correct / closer example would be:

template tempA(x: untyped) =
  let value {.inject.} = x

proc procA[T](x: T) =
  tempA(x)
  mixin value
  echo value

procA(2)

Though I don't have 1.6.16 setup to test currently. I pinged the author of the library and he was going to explore it a bit more. I suspect it might be a compiler regression for injected variables and the compiler exposing an existing bug in the library.

@SirOlaf
Copy link
Contributor

SirOlaf commented Nov 3, 2023

That would be fully untyped and work no problem. The examples I used are all correct but it is true that the one pointed out should only be valid with an expression (library has one, but the issue is the same, broken evaluation order)

@elcritch
Copy link
Contributor Author

elcritch commented Nov 7, 2023

Looks like the questionable library was able to work around it by changing one of the inner templates to return untyped. You can see it here https://github.com/codex-storage/questionable/pull/49/files.

Weird issue with typed templates, previously it would still fail if one of the template arguments was typed, now it also fails when return is typed.

It seems the core of this issue is that template with typed returns now fail.

Here's some cleaned up templates based on @SirOlaf 's example:

# works
template tempA(x: untyped): untyped =
  let value {.inject.} = 2
  value
proc procA[T](x: T) =
  discard tempA(x)
  echo value
procA(10)

# works
template tempC(x: untyped): int =
  let value {.inject.} = 2
  value
proc procC[T](x: T) =
  discard tempC(x)
  mixin value
  echo value
procC(10)

# fails on 1.6.16, works on 1.6.14
template tempB(x: untyped): int =
  let value {.inject.} = 2
  value
proc procB[T](x: T) =
  discard tempB(x)
  echo value
procB(10)

markspanbroek added a commit to codex-storage/questionable that referenced this issue Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants