erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Add `Self` type syntax #123

Closed mtshiba closed 2 years ago

mtshiba commented 2 years ago

The current Erg does not work with Self pointing to its own type. This should be replaced with the current scope type.

I have a few ideas for implementing this. One would be to replace the name in the desugaring process. Another is that when the type checker finds the type Self, it looks for its own type in the current Context.

I think the former is better, since Self needs to be replaced before the code-generating process. Some desugaring methods have already been implemented, so it would not be so difficult to implement if we refer to them.

mtshiba commented 2 years ago

I noticed that Self in the class can be replaced naively, but this does not work for Self in traits.