diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 125e1bbfb..2e998ff39 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -991,8 +991,15 @@ impl InnerResolver { } _ => unreachable!("must be list"), }; - let ty = ctx.get_llvm_type(generator, elem_ty); let size_t = generator.get_size_type(ctx.ctx); + let ty = if len == 0 + && matches!(&*ctx.unifier.get_ty_immutable(elem_ty), TypeEnum::TVar { .. }) + { + // The default type for zero-length lists of unknown element type is size_t + size_t.into() + } else { + ctx.get_llvm_type(generator, elem_ty) + }; let arr_ty = ctx .ctx .struct_type(&[ty.ptr_type(AddressSpace::default()).into(), size_t.into()], false); diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index c42c8444c..38ac9a63e 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -951,9 +951,9 @@ pub fn destructure_range<'ctx>( /// Allocates a List structure with the given [type][ty] and [length]. The name of the resulting /// LLVM value is `{name}.addr`, or `list.addr` if [name] is not specified. /// -/// Setting `ty` to [`None`] implies that the list does not have a known element type, which is only -/// valid for empty lists. It is undefined behavior to generate a sized list with an unknown element -/// type. +/// Setting `ty` to [`None`] implies that the list is empty **and** does not have a known element +/// type, and will therefore set the `list.data` type as `size_t*`. It is undefined behavior to +/// generate a sized list with an unknown element type. pub fn allocate_list<'ctx, G: CodeGenerator + ?Sized>( generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>,