#Unexpected Type Mismatch

1 messages · Page 1 of 1 (latest)

sharp badger
#

I have a struct that uses std ArrayListUnmanaged like so:

const Bar = struct {
  cols: ds.ArrayListUnmanaged(*Foo)

  fn init() @This() {
    return @This() {.cols = ds.ArrayListUnmanaged(*Foo).init()};
  }
}

// ds.ArrayListUnmanaged(*Foo).init() is simply:
fn init() @This() {
  return @This() {.list = std.ArrayListUnmanaged(T){}};
 }

calling Bar.init() results in an error:
expected type ds.ArrayListUnmanaged(*foo.Foo), found ds.ArrayListUnmanaged(*foo.Foo), which doesn't really make sense.

However, aliasing ds.ArrayListUnmanaged(*Foo) resolves the issue (i.e. const Thing = ds.ArrayListUnmanaged(*Foo)).

Any ideas?

tribal lichen
#

ds.ArrayListUnmanaged is just a wrapper around std.ArrayListUnmanaged?

sharp badger
#

Exactly

tribal lichen
#

hmm

#

while i think about this i'll suggest some style things: in Bar you can probably make init return Bar instead of @This(), while in ds.ArrayListUnmanaged you could use const Self = @This();. you only really need @This() for generics: https://zig.news/kristoff/dont-self-simple-structs-fj8

#

and in both you can use .{ fields } instead of @This() { fields } -- letting zig infer the struct type since it knows the return type

sharp badger
#

that makes sense. Will definitely refactor. Thanks.

tribal lichen
#

are Bar, Foo, and ds.ArrayListUnmanaged in three separate files?

sharp badger
#

Yeah, that's correct

tribal lichen
#

my instinct is saying that somehow "the same type imported in two different places" does not end up actually being the same type, except i don't think that should actually happen in zig

#

is your full project pushed anywhere i could take a look?

sharp badger
#

yeah, i'm really surprised by the error. It's not hosted anywhere atm. This also doesn't happen with wrappers around std.ArrayList.

cloud gyro
#

you're missing a comma after the field definition in Bar