Bug in compiler when you init a structure in default value

If you init a structure inside of the init of a class you get this error:

Example Code:

   class MyClass {
	
	struct Options {
		var port: Int? = nil
		var pingInterval: UInt16 = 10
		var useTLS = false

		var concretePort: Int {
			return port ?? (useTLS ? 8883 : 1883)
		}

	}
 
	private var options: Options
	private var host: String
	
	init(host: String, options: Options = Options()) {
		self.host = host
		self.options = options
	}
}

Screenshot:

btw, pro tip, Cmd-Option-C lets you copy code + error messages, in Fire.

1 Like

i don’t believe we (currently) support non-constant default parameters; in fact, i’m not even sure of that can be supported on Java and .NET, ut i’ll check with the compiler team (and this should err better)

Thanks, logged as bugs://78125

1 Like

Hello , but anyway the compiler should support all the feature. to compile everything you have in original swift compiler.
It’s shouldn’t be depend on the platform because it’s syntax error.

Should, yes, thats why i logged a bug. Carlo tells me that we do indeed support non-const default arguments, and this is an unrelated bug, which will be fixed. that said:

well, some things will, because the compiler cant do stuff that the platform won’t allow. :wink:

To give an (unrelated to this) example, .NET has stricter tules for what a constructor (ie init()) can die before it has called the base constructor. No mater what Swift/Xocde allows you to do, if you want to get a valid .NET executable, you’ll have to live with he limit .NET imposes, there.

bugs://78125 got closed with status fixed.

Do you have a more complete testcase? I couldn’t reproduce this issue.