Self should be evaluated upon reference, not definition
Currently defining Self in an object will result in it being evaluated immediately. This means that the compiler thinks that SomeTrait.new
returns Object
(Object.new
is defined as def new -> Self
), instead of SomeTrait
. This prevents you from writing code such as this:
# Imagine this process being sent multiple, different objects, all implementing SomeTrait
let obj = process.receive as SomeTrait
obj.new
One example would be std::test
. Here we might send a group of test cases (which would all implement a common trait) to a process to execute. This process doesn't know the concrete types, and using Object
as the type wouldn't cut it.
Fortunately you can work around this, though it's a bit messy:
let obj = process.receive as SomeTrait
let instance = obj.new as SomeTrait
instance.something
Edited by Yorick Peterse