FascinatedBox / lily

Interpreted language focused on expressiveness and type safety.

Home Page:http://lily-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Forward declarations

FascinatedBox opened this issue · comments

This is one of those more obvious features that I never got around to. The syntax I'd like to see is:

forward [public/protected/private]? define <name>(args): return type { ... }

I'm particular about { ... } being included at the end of a forward declaration so the declaration doesn't seem empty. It's rather strange to see:

class Example {
    forward define x(y: Integer)
}

The { ... } makes it clear from scrolling through that the method is forward, and not that the method is somehow missing the body.

I think that forward declarations should be finished up at the end of their scope. This means that modules would NOT be allowed to forward declare functions of other modules. Not that they really could, given namespace scoping. The same holds for classes and enums.

Errors from incomplete forward declarations should be done at the end of a scope. This means that a user importing several files that have conflicts may receive several batches of errors. However, in return, the user can be assured that if some file is successfully parsed, that there is no hidden incomplete forward declaration lurking in the shadows. I very much want to avoid the 'cascade of linker errors at the very end' that C has.

I also want to specify that the ordering should be with 'forward' always before public/protected/private. That is, not allowing 'public forward' so that there's no argument/question over how to do it.