Casting self
to a trait inside a default method is unsound
#787
Labels
Milestone
self
to a trait inside a default method is unsound
#787
Please describe the bug
When defining a default method in a trait, we currently allow one to cast or move
self
into a trait. For example:This is unsound if the trait is implemented for a type which can't be cast to a trait, such as
Int
or aninline
type as introduced per 8ca46bf and #783.The mentioned PR introduces a
self_type
field on theTraitInstance
structure, which we can use to detect if some type isself
or not. This in turn can be used to disallow such casts. For example:Applying the above diff introduces another problem:
std.iter.Peekable
is implemented such that it expects a boxedIter
value as its input. This means thatstd.iter.Iter.peekable
becomes invalid with the above diff applied, with no suitable workaround. To resolve that, we also need to re-introduceSelf
as a type such thatpeekable()
can be implemented asfn pub move peekable -> Peekable[T, Self]
with thePeekable
signature changed toPeekable[T, I: mut + Iter[T]]
.Blocked by
Operating system
Fedora
Inko version
main
The text was updated successfully, but these errors were encountered: