Silver: For loop before the super.init call causes 'self' cannot be accessed before inherited init called


(Taras Vozniuk) #1

IDE: Fire
Version: 9.0.97.2071, 9.1.100.2076
Target: Java
Description:

Bookshelf contains a for loop before super.init call. The compiler will complain when it sees it with: error E155: "self" cannot be accessed before the inherited constructor has been called

public class LabeledShelf {
	
	public var label: String
	public init(label: String){
		self.label = label
	}
}

public class Bookshelf: LabeledShelf {
	
	var books: [String]
	init(books: [String], label: String){
		
                //don't seem to like for loops before super.init
		for i in 0 ..< 10 {
		}
		
		#if COOPER
			super.init(label: label)
		#endif
		
		self.books = books
			
		#if !COOPER
			super.init(label: label)
		#endif
	}
}

(Carlo Kok) #2

Java and .NET don’t allow complex constructs before calling super.init.


(Taras Vozniuk) #3

didn’t know that, good to know, thanks!


(RemObjects) #4

Thanks, logged as bugs://77008 (to improve the error message)


(RemObjects) #5

bugs://77008 got closed with status fixed.