Issue 160: invalid optional arguments for interface
Status:  Fixed
Owner: ----
Closed:  Apr 2012
Reported by franco.p...@gmail.com, Mar 13, 2012
What steps will reproduce the problem?
try compiling this:
interface IArg
{
	public function optArgSequence(?opt : String, mand : String) : Void;
}

What is the expected output? What do you see instead?
Should compile.

An equivalent class (not implementing the above interface) will work and that should be valid syntax for haxe.

Mar 15, 2012
Project Member #1 gameh...@gmail.com
Has this changed recently? I'm trying to compile for neko:

class Test
{
	public static function optArgSequence(?opt : String, mand : String) : Void
   {
      trace(opt + "/" + mand);
   }


   public static function main()
   {
      optArgSequence("a");
      optArgSequence("a","b");
   }
}


and it does not work: Test.hx:11: characters 6-25 : Function 'optArgSequence' requires arguments : ?opt, mand
Mar 15, 2012
#2 franco.p...@gmail.com
It is not about the argument type but the optional argument position; the sample above was not meant to be used, only to prove that is failing to compile on CPP (it compiles on Neko) and the problem is in the Interface not in the instance/static methods. See the example below for a fully working/nonworking example: 


class Main
{
	static function main()
	{
		var inst = new Arg();
		inst.optArgSequence("mand");
		inst.optArgSequence(7, "mand");
	}
}

class Arg implements IArg
{
	public function new() {}
	public function optArgSequence(?opt : Int, mand : String) : Void
	{

	}
}

interface IArg
{
	public function optArgSequence(?opt : Int, mand : String) : Void;
}


This works for neko but not for CPP. If you remove the interface entirely, it works fine for CPP too.
Mar 15, 2012
Project Member #3 gameh...@gmail.com
Ok, it does not work with ?String,String (haxe bug ?) but I see the problem with ?Int/String.
Mar 15, 2012
#4 franco.p...@gmail.com
?String, String fails by design ... the typer forces the first matching argument leaving the second generating an error. It still correct syntax since you can pass null, "somehting" but obviously pretty useless.
Apr 4, 2012
Project Member #5 gameh...@gmail.com
Should be fixed in haxe svn - thanks for the code.
Status: Fixed