D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7702 - opDispatch goes into infinite loop
Summary: opDispatch goes into infinite loop
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 critical
Assignee: No Owner
URL:
Keywords: ice, pull
Depends on:
Blocks:
 
Reported: 2012-03-13 06:29 UTC by Michal Minich
Modified: 2012-03-15 15:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Michal Minich 2012-03-13 06:29:49 UTC
struct S {
    template opDispatch (string name) {
        void opCall (T) () @property {}
    }
}

struct S3 {
    auto opCall (T) () @property {
        struct S4 {
            void opDispatch (string name) () @property {}
        }
        S4 s4;
        return s4;
    }
}
void main () {
    S s;
    s.opDispatch!"x".opCall!int;  // OK
    s.x.opCall!int;               // OK
    s.opDispatch!("x")!(int);     // parse error
    s.x!int;                      // infinite loop in dmd

    S3 s3;
    s3.opCall!int.opDispatch!("x");  // OK
    s3.opCall!int.x;                 // OK
    s3!int.x;       // Error: template instance s3!(int) s3 is not a template declaration, it is a variable
}
Comment 1 Kenji Hara 2012-03-13 07:30:50 UTC
The infinite loop in dmd is the real issue.

struct S {
   template opDispatch (string name) {
       //void opCall (T) () @property {}  // not need
   }
}
void main () {
    S s;
    s.x!int;   // infinite loop in dmd
}

And others are not errors, because their error messages are valid.
Then I replace the subject.

----

opCall works only for call syntax, e.g. rewriting foo(args) to foo.opCall(args).

If you want to implement s.x!int with opDispatch, *nested opDispatch idiom* like follows would work.

struct S {
    template opDispatch(string name) {
        T opDispatch(T)() @property {
            return T.init;
        }
    }
}
void main() {
    S s;
    assert(s.x!int == 0);
    // same as s.opDispatch!("x").opDispatch!(int)()
}
Comment 3 github-bugzilla 2012-03-15 15:05:24 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/380b2f8a26da0cb5c6a263608efb2c7020f25c7e
Merge pull request #808 from 9rnsr/fix7702

Issue 7702 & 5733 - opDispatch goes into infinite loop