vsl-lang/VSL

Class initalizers

vihanb opened this issue · 6 comments

Classes don't have initalizers, they'll need to support:

  • Optional returns init?
  • Compilation <name>.init.<params>

Validation and other problems are to be solved.

Examples:

public init?(a: T?) {
    if a == T.b { return nil }
    self.a = a
}

Additionally field initalization and super() order checks should be implemented

I don't think init is a good idea, IMO we should make it like C# and make constructor name same as class name, plus returns with a value aren't allowed in initializers

@somebody1234 it is nullable intalizer so that why it is returning

shit wrong issue :||||

Wrong issue. :P

So I take it that the constructor syntax would be something like this then:

public class A {
    public init?(args) {
        self(other args)
        if(something bad) {
            return nil
        }
    }

    private init(args) {
        super(other args)
        do some stuff
    }
}

that looks good. (the init(args)) would probably need to specify types but I assume you're using the function param list for initalizers anyway