Closed iacore closed 2 years ago
{.experimental: "notnil".}
import tables
type FooObject = object
type Foo = ref FooObject not nil
type Bar = object
table: Table[int, Foo]
proc `=init`(x: var Foo) =
x = new(Foo)
let foo: Foo
Error: 'let' symbol requires an initialization
Use =init hook or some other proc for the default value.
There is no =init
hook in today's Nim. The RFC hasn't been implemented.
Error: 'let' symbol requires an initialization
That's not a bug either.
Function
echo
outputs the wrong string.Example
Current Output
What's wrong
1
There should be some way to specify default value of
not nil
reference type.2
The error message doesn't tell why
table
can't be initialized.3
yields the compile error
not
Possible Solution
Use
=init
hook or some otherproc
for the default value.Additional Information
This is related to https://nim-lang.github.io/Nim/manual_experimental_strictnotnil.html This is related to user defined default value.