Skip to content

Commit

Permalink
fixes #23419; internal error with void in generic array instantiation (
Browse files Browse the repository at this point in the history
…#23550)

fixes #23419

`void` is only supported as fields of objects/tuples. It shouldn't allow
void in the array.

I didn't merge it with taField because that flag is also used for
tyLent, which is allowed in the fields of other types.
  • Loading branch information
ringabout committed May 1, 2024
1 parent d09c3c0 commit 185e06c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions compiler/typeallowed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type
taProcContextIsNotMacro
taIsCastable
taIsDefaultField
taVoid # only allow direct void fields of objects/tuples

TTypeAllowedFlags* = set[TTypeAllowedFlag]

Expand Down Expand Up @@ -60,6 +61,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
if typ == nil: return nil
if containsOrIncl(marker, typ.id): return nil
var t = skipTypes(typ, abstractInst-{tyTypeDesc, tySink})

let flags = if t.kind == tyVoid: flags else: flags-{taVoid}
case t.kind
of tyVar, tyLent:
if kind in {skProc, skFunc, skConst} and (views notin c.features):
Expand Down Expand Up @@ -115,7 +118,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
of tyStatic:
if kind notin {skParam}: result = t
of tyVoid:
if taField notin flags: result = t
if taVoid notin flags: result = t
of tyTypeClasses:
if tfGenericTypeParam in t.flags or taConcept in flags: #or taField notin flags:
discard
Expand Down Expand Up @@ -184,12 +187,12 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
t.baseClass != nil and taIsDefaultField notin flags:
result = t
else:
let flags = flags+{taField}
let flags = flags+{taField, taVoid}
result = typeAllowedAux(marker, t.baseClass, kind, c, flags)
if result.isNil and t.n != nil:
result = typeAllowedNode(marker, t.n, kind, c, flags)
of tyTuple:
let flags = flags+{taField}
let flags = flags+{taField, taVoid}
for a in t.kids:
result = typeAllowedAux(marker, a, kind, c, flags)
if result != nil: break
Expand Down
5 changes: 5 additions & 0 deletions tests/errmsgs/t23419.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
discard """
errormsg: "invalid type: 'void' in this context: '(array[0..-1, void],)' for var"
"""

var a: (array[0, void], )

0 comments on commit 185e06c

Please sign in to comment.