Dependent default types
tetotechy opened this issue · 4 comments
This isn't an actionable bug. In keeping with our getting help documentation, please ask "how do I" questions in the Zulip.
Closing
Apologies for not making myself clear. What I meant is that the following code compiles (I changed the example a bit):
actor Main
new create(env: Env) =>
Foo[U8, Array[U8]](env, 10)(3)
class Foo[T: Stringable val, Arr: Seq[T] ref = Array[T]]
let _env: Env
var arr: Arr = Arr
new create(env: Env, v: T) =>
_env = env
arr.push(v)
fun ref apply(v: T) =>
arr.push(v)
for el in arr.values() do
_env.out.print(el.string())
end
whilst omitting the second generic type when instantiating - to leverage the default type, the compiler gives an error:
actor Main
new create(env: Env) =>
Foo[U8](env, 10)(3)
class Foo[T: Stringable val, Arr: Seq[T] ref = Array[T]]
let _env: Env
var arr: Arr = Arr
new create(env: Env, v: T) =>
_env = env
arr.push(v)
fun ref apply(v: T) =>
arr.push(v)
for el in arr.values() do
_env.out.print(el.string())
end
No problems to revert to Zulip, happy to do so if this is expected behavior. Thanks!
This is definitely something that I would have expected to work as desired.
The key issue here is that the compiler is comparing the constraint Seq[U8]
to the default arg Array[T]
. But to make this compile correctly it would either need to compare Seq[T]
withArray[T]
or alternatively, Seq[U8]
with Array[U8]
.
We discussed this a bit in the sync call today, but haven't done any triaging yet into why this doesn't work as expected today. Needs further troubleshooting.