It also just dawned on me that multiple interfaces are not currently supported on an anonymous class, but (I think) could be:
namespace MultiInterfaces;
type
SuperFoo = class
public
method Bar; virtual; empty;
end;
IFoo1 = interface
method Bar;
end;
IFoo2 = interface
method Bar;
end;
Program = class
public
class method Main(args: array of String): Int32;
begin
var o := new interface IFoo1, IFoo2 ( IFoo1.Bar := method begin end,
IFoo2.Bar := method begin end );
end;
end;
The above obviously does not currently compile. The same technique for resolving interface methods could be applied when implementing an interface on a subclass with overridden methods:
var o := new class SuperFoo, IFoo2
(
Bar := method begin end, // Overrides SuperFoo.Bar
IFoo2.Bar := method begin end // Implements IFoo2.Bar
);
Interface method implementations would require qualification to differentiate them from overrides of methods inherited from the base class.
The incantation could obviously still use new interface SuperClass, Interface1
if it had to.
I may be missing something, but I wonder if a more capable new class
syntax couldn’t simply co-exist alongside the existing `new interface’ syntax (which might then be officially deprecated, but still supported for backward compatibility) ?
AIUI the current support provides that when the compiler encounters:
new interface <TypeName> ( .. );
If TypeName identifies a class then it’s an anon subclass of TypeName.
If TypeName identifies an interface then it’s an anon subclass of Object that implements TypeName.
Extending a base class and implementing an interface on the anon subclass is not currently supported:
new interface <BaseClass>, <Interface> (); // Not supported
Meanwhile when the compiler encounters:
new class ( .. );
Then this always implements an anon subclass of Object with some inline declared properties. This would be the special case for the new class
syntax.
Otherwise, any new class <BaseClass>
could not introduce any new properties and could only pass parameters to any inherited public ctors, followed by extension parameters to initialise public properties/members and/or implement or override inherited or declared interface methods).
The only slight wrinkle would be that these would be equivalent:
new interface <BaseClass> ();
new class <BaseClass> ();
The first being the current support for subclassing and overriding methods. AFAICS this could continue to be supported, but all the more sophisticated capabilities of anonymous subclassing, passing params to inherited ctors, implementing interface(s) etc would require the new class
syntax.
In case you can’t tell, I quite enjoy thinking about language 'design" (if you can call off the cuff invention of syntax without consideration of existing compiler constraints and implementation details ‘design’ ).