Summary: [tdpl] Multiple delegate-related issues (literal
                    syntax, @system deduction)
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Andrei Alexandrescu <> 2011-12-18 
21:08:50 PST ---
This is a copy of a failing TDPL example. First, the compiler doesn't accept
the delegate literal syntax unless it includes the keyword "delegate". Fixing
that somehow makes the compiler decide the literal is @system and refuses
binding it.

module test;// Context begin
#line 1369 "0900-operators.tex"
import std.variant;

alias Variant delegate(Dynamic self, Variant[] args...) DynMethod;
// Context end
// Context begin
#line 1383 "0900-operators.tex"
class Dynamic {
   private DynMethod[string] methods;
   void addMethod(string name, DynMethod m) {
      methods[name] = m;
   void removeMethod(string name) {
   // Dispatch dynamically on method
   Variant call(string methodName, Variant[] args...) {
      return methods[methodName](this, args);
   // Provide syntactic sugar with opDispatch
   Variant opDispatch(string m, Args)(Args args...) {
      Variant[] packedArgs = new Variant[args.length];
      foreach (i, arg; args) {
         packedArgs[i] = Variant(arg);
      return call(m, args);
// Context end
#line 1409 "0900-operators.tex"
unittest {
  import std.stdio;
  auto obj = new Dynamic;
      delegate Variant(Dynamic, Variant[]) {
        writeln("Hello, world!");
        return Variant();
  obj.sayHello();  // Prints "Hello, world!"

void main(){}

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to