* fixes #20699; generate an empty struct for void type * Add docs and test case.
This commit is contained in:
parent
6894a00409
commit
8fcb9380f0
2 changed files with 28 additions and 11 deletions
|
|
@ -514,7 +514,10 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
|
||||||
let structName = "_" & mangleRecFieldName(m, n[0].sym) & "_" & $i
|
let structName = "_" & mangleRecFieldName(m, n[0].sym) & "_" & $i
|
||||||
var a = newRopeAppender()
|
var a = newRopeAppender()
|
||||||
genRecordFieldsAux(m, k, rectype, check, a, unionPrefix & $structName & ".")
|
genRecordFieldsAux(m, k, rectype, check, a, unionPrefix & $structName & ".")
|
||||||
if a != "":
|
# When 'k' is 'void', 'a' is the empty string and we just generate
|
||||||
|
# empty struct. This prevents field access errors when generating
|
||||||
|
# static initializers for the type.
|
||||||
|
# See issue #20699
|
||||||
if tfPacked notin rectype.flags:
|
if tfPacked notin rectype.flags:
|
||||||
unionBody.add("struct {")
|
unionBody.add("struct {")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -476,6 +476,20 @@ template main {.dirty.} =
|
||||||
|
|
||||||
foo2()
|
foo2()
|
||||||
|
|
||||||
|
block: # issue #20699
|
||||||
|
type
|
||||||
|
Either[A,B] = object
|
||||||
|
case kind:bool
|
||||||
|
of false:
|
||||||
|
b: B
|
||||||
|
of true:
|
||||||
|
a: A
|
||||||
|
O = object of RootRef
|
||||||
|
|
||||||
|
proc oToEither(o:O):Either[O,void] =
|
||||||
|
Either[O,void](kind:true,a: o)
|
||||||
|
|
||||||
|
discard oToEither(O())
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue