codex-storage / questionable

Elegant optional types for Nim
Other
116 stars 5 forks source link

Weird Windows compile error #39

Closed elcritch closed 1 year ago

elcritch commented 1 year ago

This error keeps popping up every so often where the $ in https://github.com/codex-storage/questionable/blob/1569ef4526d118c1bd1c31d8882eb9de6193a096/questionable/withoutresult.nim#L25 breaks:

https://github.com/codex-storage/nim-codex/actions/runs/5720835236/job/15501441283#step:8:386

It seems to only happen on Windows, which is really weird. I tried swapping without to use repr on the PR'ed I'd created and I think that had resolved it.

elcritch commented 1 year ago

Here's the stacktrace:

D:\a\nim-codex\nim-codex\codex\node.nim(137, 25) template/generic instantiation of `async` from here
D:\a\nim-codex\nim-codex\codex\node.nim(186, 3) Warning: unreachable code after 'return' statement or '{.noReturn.}' proc [UnreachableCode]
D:\a\nim-codex\nim-codex\codex.nim(47, 25) template/generic instantiation of `load` from here
D:\a\nim-codex\nim-codex\codex.nim(52, 22) template/generic instantiation of `addConfigFile` from here
D:\a\nim-codex\nim-codex\vendor\nim-confutils\confutils.nim(847, 39) template/generic instantiation of `loadFile` from here
D:\a\nim-codex\nim-codex\vendor\nim-toml-serialization\toml_serialization.nim(169, 13) template/generic instantiation of `readValue` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization.nim(30, 9) template/generic instantiation of `readValue` from here
D:\a\nim-codex\nim-codex\vendor\nim-toml-serialization\toml_serialization\reader.nim(478, 8) template/generic instantiation of `decodeInlineTable` from here
D:\a\nim-codex\nim-codex\vendor\nim-toml-serialization\toml_serialization\reader.nim([356](https://github.com/codex-storage/nim-codex/actions/runs/5720835236/job/15501441283#step:8:357), 19) template/generic instantiation of `fieldReadersTable` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization\object_serialization.nim(256, 34) template/generic instantiation of `makeFieldReadersTable` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization\object_serialization.nim(218, 26) template/generic instantiation of `enumAllSerializedFields` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization\object_serialization.nim(152, 32) template/generic instantiation of `enumAllSerializedFieldsImpl` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization\object_serialization.nim(235, 52) template/generic instantiation of `readFieldIMPL` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization\object_serialization.nim(203, 13) template/generic instantiation of `readValue` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization.nim(30, 9) template/generic instantiation of `readValue` from here
D:\a\nim-codex\nim-codex\vendor\nim-toml-serialization\toml_serialization\reader.nim(424, 19) template/generic instantiation of `readValue` from here
D:\a\nim-codex\nim-codex\vendor\nim-serialization\serialization.nim(29, 19) Warning: The 'ValidIpAddress' type doesn't have a valid default value [UnsafeDefault]
stack trace: (most recent call last)
D:\a\nim-codex\nim-codex\vendor\questionable\questionable\withoutresult.nim(25, 26) without
D:\a\nim-codex\nim-codex\vendor\nimbus-build-system\vendor\Nim\lib\core\macros.nim(1382, 5) $
D:\a\nim-codex\nim-codex\codex.nim(47, 25) template/generic instantiation of `load` from here
D:\a\nim-codex\nim-codex\vendor\nim-confutils\confutils.nim(1145, 13) template/generic instantiation of `loadImpl` from here
D:\a\nim-codex\nim-codex\vendor\nim-confutils\confutils.nim(895, 50) template/generic instantiation of `configurationRtti` from here
D:\a\nim-codex\nim-codex\vendor\nim-confutils\confutils.nim(696, 19) template/generic instantiation of `setField` from here
D:\a\nim-codex\nim-codex\vendor\nim-confutils\confutils.nim(606, 27) template/generic instantiation of `parseCmdArgAux` from here
D:\a\nim-codex\nim-codex\vendor\nim-confutils\confutils.nim(539, 14) template/generic instantiation of `parseCmdArg` from here
D:\a\nim-codex\nim-codex\codex\conf.nim(299, 59) Error: Invalid node kind nnkStmtList for macros.`$`
markspanbroek commented 1 year ago

I think I found the root cause for this. In nim-results a template err is defined without parameters. This gets evaluated before the without macro is evaluated. This means that code like this:

import pkg/results # exports a template `err` with no parameters

without condition, err: 
  discard

Looks like this to the without macro:

without condition, err(typeof(result)):
  discard

I don't think we can do much in questionable to handle this, because we only see the AST after the err template has been evaluated. I improved the error message in #40, so hopefully that will help users to find out what's wrong, and use a different name for the error variablle.