Nim: Error: usage of 'isNil' is a user-defined error

Created on 9 Jun 2019  路  4Comments  路  Source: nim-lang/Nim

test.nim

var a: string = "foo"
echo a.isNil
$ nim -r c test.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
test.nim(2, 8) Error: usage of 'isNil' is a user-defined error

OS: Manjaro (Arch Linux)

$ nim -v
Nim Compiler Version 0.19.6 [Linux: amd64]
Compiled at 2019-05-14
Copyright (c) 2006-2018 by Andreas Rumpf

active boot switches: -d:release -d:nativeStackTrace

I can't understand how is it that a function as common as that doesn't work. Am I doing something wrong?

btw I noticed the version says it's compiled for an amd, but I'm running an x86-64

Error messages

Most helpful comment

I suggest removing the function on strings from the standard library since it doesn't make sense. Also on seqs which also seem to not work anymore.

All 4 comments

It's because a string cannot be nil. You need to compare with "" or look into using options stdlib module.

https://scripter.co/notes/nim/#nil-string

I suggest removing the function on strings from the standard library since it doesn't make sense. Also on seqs which also seem to not work anymore.

Works with ref

~~~nim
type Obj = ref object
v: string

var a: Obj = Obj(v: "foo")
echo a.isNil
~~~

Doesn't work with seq

~nim
var a: seq[int] = @[1]
echo a.isNil
~

Looks like the isNil procs for strings and seqs still exist so that --nilseqs:on works during the transition period of this deprecation:

https://github.com/nim-lang/Nim/blob/bce908f6ee9f24346641310d8f7f8971e92ffe01/changelogs/changelog_0_19_0.md#L180-L181

https://github.com/nim-lang/Nim/blob/bce908f6ee9f24346641310d8f7f8971e92ffe01/lib/system.nim#L2828-L2838

Was this page helpful?
0 / 5 - 0 ratings

Related issues

capocasa picture capocasa  路  3Comments

hlaaftana picture hlaaftana  路  3Comments

kobi2187 picture kobi2187  路  4Comments

Vindaar picture Vindaar  路  3Comments

SolitudeSF picture SolitudeSF  路  3Comments