Something has changed on the Parameter world. Previously, Traits with aliases work perfect. I used to combine it with structs to get really good dynamism, but now, somehow the compiler is failing when it needs to use trait aliases in certain places. Example:
trait WithAnAlias:
alias A: AnyType
# Struct that conforms to `WithAnAlias`
struct SomeStruct(WithAnAlias):
alias A = Int
# Needs a struct that conforms to `WithAnAlias`
# Will assing a and b automatically
struct SomeWrapper[t: WithAnAlias, a: AnyType, b: AnyType]:
fn __init__(out self: SomeWrapper[t, t.A, t.A]):
pass
fn main():
_sw = SomeWrapper[SomeStruct]()
# invalid initialization: could not deduce parameter 'b' of parent struct 'SomeWrapper'
I recently noticed some function called get_witness
that I didn’t see in the past. I’m not sure if it’s related to it, but now this code is not working. If we use only 1 parameter, it works.
struct SomeWrapper[t: WithAnAlias, a: AnyType]:
fn __init__(out self: SomeWrapper[t, t.A]):
pass
fn main():
_sw = SomeWrapper[SomeStruct]()
All good now. But why in the first case it didn’t work?
Related issue: https://github.com/modular/modular/issues/5016