#[solved] '[][]const u8' does not support array initialization syntax

1 messages ยท Page 1 of 1 (latest)

red flame
#
bin/.lib/confy/src/confy/dependency.zig:93:60: error: type '[][]const u8' does not support array initialization syntax
  if (!arg.root) return try confy.command.ArgList.create(&.{"--dep", dep.name}, trg.A.allocator());
                                                          ~^~~~~~~~~~~~~~~~~~~
bin/.lib/confy/src/confy/dependency.zig:93:60: note: inferred array length is specified with an underscore: '[_][]const u8'
const ArgList = struct {
  const Slice = std.ArrayListUnmanaged(T).Slice;
  fn create (items :*const Slice, A :std.mem.Allocator) ArgList { ..... }
};

Extremely confused by this error ๐Ÿ˜•
What am I even supposed to do here? ๐Ÿงฉ

proven mirage
#

the function takes *const Slice which is *const [][]const u8. it sees the & you're passing and assumes the .{ ... } is meant to be a Slice ([][]const u8)

#

*const Slice seems like a mistake with the pointer and weird regardless, why not just use a normal slice type directly?

red flame
#

Oh, I think I see why:

dependency.zig:93:58: error: expected type '[][]const u8', found '*const [2][]const u8'
  if (!arg.root) return try confy.command.ArgList.create(&.{"--dep", dep.name}, trg.A.allocator());
                                                         ^~~~~~~~~~~~~~~~~~~~~
dependency.zig:93:58: note: cast discards const qualifier
sequence.zig:61:32: note: parameter type declared here
  pub fn create (items :@This().Slice, allocator :std.mem.Allocator) !@This() {
#

I'm really lost in how I'm supposed to fix the const cast error now ๐Ÿค”

proven mirage
#

how is items used in the function?

red flame
#
    var result = try @This().create_capacity(items.len, allocator);
    result.buffer.appendSliceAssumeCapacity(items);
    return result;
proven mirage
#

just use []const T, arraylist.slice is mutable but you don't need it to be mutable

red flame
#

ic

delicate prism
#

&.{ "test", "bla" } is []const []const u8 not [][]const u8

  var what: []const []const u8 = &.{ "test", "bla" };
red flame
#

it seems to have gone past the error when using []const T for the type of items

#

tysm ๐Ÿ™ I was so lost