-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Since types are evaluated at the class level, the type self will typically refer to the class that the method is defined on. For example here the self return value refers to Example.
class Example
fun foo => self do
self
end
endThis works, but the signature could be more precise. For example, if the function returns another Example object instead of returning itself, it would still be valid.
class Example
fun foo => self do
Example.new
end
endThat’s because self here means Example. It’s equivalent to
class Example
fun foo => Example do
Example.new
end
endBut what if we want to type a function that actually returns itself? There should be a way to do that.
I think we should introduce itself as a special type like never and void. itself refers to the self that the method is bound to. With itself, this would be valid:
class Example
fun foo => itself do
self
end
endBut this would not:
class Example
fun foo => itself do
Example.new
end
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels