From d372a0030dafdd3ca734f996607091eda5c62c95 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 1 May 2024 15:02:43 +0800 Subject: [PATCH] fixes #23419; internal error with void in generic array instantiation (#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. (cherry picked from commit 185e06c92362083c06c76f87e325889b1c9dc659) --- compiler/typeallowed.nim | 7 +++++-- tests/errmsgs/t23419.nim | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/errmsgs/t23419.nim diff --git a/compiler/typeallowed.nim b/compiler/typeallowed.nim index 2872f66db2..5c1ba77e13 100644 --- a/compiler/typeallowed.nim +++ b/compiler/typeallowed.nim @@ -27,6 +27,7 @@ type taProcContextIsNotMacro taIsCastable taIsDefaultField + taVoid # only allow direct void fields of objects/tuples TTypeAllowedFlags* = set[TTypeAllowedFlag] @@ -58,6 +59,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): @@ -113,7 +116,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 @@ -184,7 +187,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, t.kind == tyObject and t[0] != nil and taIsDefaultField notin flags: result = t else: - let flags = flags+{taField} + let flags = flags+{taField, taVoid} for i in 0..