binding-tools-for-swift icon indicating copy to clipboard operation
binding-tools-for-swift copied to clipboard

swift has changed it's constructor inheritance rules

Open stephen-hawley opened this issue 5 years ago • 0 comments

In NewClassCompilerTests.WatchThoseConstructors, apparently you only have to override the ctors in your immediate parent? Test code:

open class Bass {
	private var x:Int32;
	public init (a: Int32) {
		x = a
	}
	public init (a: Int32, b: Int32) {
		x = a + b
	}
	public func getX() -> Int32 {
		return x
	}
}
open class Mid : Bass {
	public override init (a: Int32, b: Int32) {
		super.init (a:a, b: b)
	}
}

Wrapping code for Mid:

import NewClassCompilerTests
import Swift
public final class xam_sub_Mid : Mid
{

    private var
    _xamarinClassIsInitialized: Bool =
        false;
    public override init(a: Int32, b: Int32)
    {
        super.init(a: a, b: b);

        _xamarinClassIsInitialized = true;
    }
    public override init(a: Int32)
    {
        super.init(a: a);

        _xamarinClassIsInitialized = true;
    }
}

Error message from the compiler:

NewClassCompilerTests-Mid.swift:16:21: error: initializer does not override a designated initializer from its superclass
    public override init(a: Int32)
           ~~~~~~~~ ^

stephen-hawley avatar Oct 28 '20 20:10 stephen-hawley