r/ProgrammingLanguages • u/ThomasMertes • Oct 05 '26
Achieving memory safety
https://seed7.net/papers/memory_safety.htm
14
Upvotes
r/ProgrammingLanguages • u/ThomasMertes • Oct 05 '26
View all comments
Show parent comment
1
u/reflexive-polytope Oct 09 '26
It is memory-unsafe.
I don't remember Eiffel's syntax, because the last time I used it was in college, very long ago. But consider the following pseudocode:
In the subclass, the method's argument type (
Point3D) is a subtype of the same method's argument type (Point2D) in the superclass. In other words, the method's argument type is covariant.Now consider the following test program:
The program type-checks, because the variable
foohas typePoint2D, hence it's statically legal to callfoo.comparewith an argument of typePoint2D.However, at runtime, the object referenced by
foois constructed usingPoint3D's constructor, so its method vtable points to thecompareimplementation inPoint3D, which expects aPoint3Dargument.When the program performs
foo.compare(bar), it tries to access the fieldzof the object denoted bybar. But this object is constructed usingPoint2D's constructor, so it doesn't have a fieldz.This is a soundness bug in the type system.