Open mynameisdaniil opened 1 year ago
Can you provide a reduced assertive source code repro sample ?.
@juancarlospaco Sorry, I was trying to make minimal working example, but was unable to. But I can assist you with the codebase where this bug is reproducible.
Repro:
protocol.nim
:
{.push raises: [].}
import
"."/[node]
import
std/[options, sugar]
var closestNodes: seq[Node]
for cn in closestNodes:
discard cn.address.map(a => a.port)
node.nim
import std/options
type
Address* = object
port*: int
Node* = ref object
address*: Option[Address]
On 1.6 (any version I tried, up to current version-1-6
from branch):
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
2.0 and devel don't seem to have this problem.
Example Nim versions:
SIGSEGV upon compilation:
Nim Compiler Version 1.6.21 [Linux: amd64]
Compiled at 2024-05-27
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 38640664088251bbc88917b4bacfd86ec53014b8
active boot switches: -d:release
No SIGSEGV:
Nim Compiler Version 2.0.5 [Linux: amd64]
Compiled at 2024-05-27
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: ab053fd56a6517531441cdbf0be5536189831c9c
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-05-27
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: daad06bd07ff11cc2b0c74b604ff82899e923d59
active boot switches: -d:release
Description
I've been trying to use some functional style programming to access type lifted into
Option
.If you re-arrange this code differently i.e. move
map((a) => $a.port).get("0")
part into separate proc this issue goes away. Which makes me think it is somehow connected to type inference.To replicate this:
Nim Version
Nim Compiler Version 1.6.16 [MacOSX: arm64] Compiled at 2023-10-12 Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 3c9b68dc157804885b14a1984efc25e8b7cc861d active boot switches: -d:release
Current Output
Expected Output
No response
Possible Solution
No response
Additional Information
No response