mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-19 01:18:32 +00:00
fixes #2355
This commit is contained in:
@@ -1904,7 +1904,8 @@ proc checkInitialized(n: PNode, ids: IntSet, info: TLineInfo) =
|
||||
of nkOfBranch, nkElse: checkInitialized(lastSon(n.sons[i]), ids, info)
|
||||
else: internalError(info, "checkInitialized")
|
||||
of nkSym:
|
||||
if tfNeedsInit in n.sym.typ.flags and n.sym.name.id notin ids:
|
||||
if {tfNotNil, tfNeedsInit} * n.sym.typ.flags != {} and
|
||||
n.sym.name.id notin ids:
|
||||
message(info, errGenerated, "field not initialized: " & n.sym.name.s)
|
||||
else: internalError(info, "checkInitialized")
|
||||
|
||||
|
||||
14
tests/notnil/tnotnil_in_objconstr.nim
Normal file
14
tests/notnil/tnotnil_in_objconstr.nim
Normal file
@@ -0,0 +1,14 @@
|
||||
discard """
|
||||
errormsg: "field not initialized: bar"
|
||||
line: "13"
|
||||
"""
|
||||
|
||||
# bug #2355
|
||||
type
|
||||
Foo = object
|
||||
foo: string not nil
|
||||
bar: string not nil
|
||||
|
||||
# Create instance without initializaing the `bar` field
|
||||
var f = Foo(foo: "foo")
|
||||
echo f.bar.isNil # true
|
||||
Reference in New Issue
Block a user