Bug 20860 – OpDispatch does not work for structs with constructor and destructor
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-24T11:43:32Z
Last change time
2021-12-14T10:34:11Z
Keywords
pull
Assigned to
No Owner
Creator
Szabo Bogdan
Comments
Comment #0 by contact — 2020-05-24T11:43:32Z
It looks like opDispatch does not work in this case:
```
struct A
{
this(int a) {}
///
void opDispatch(string methodName, Params...)(Params params) {
}
~this() {}
}
void main()
{
A(3).test();
}
```
Comment #1 by b2.temp — 2020-05-24T12:16:57Z
that's an old regression (2.065). Curiously that works when you remove the parens of the call ( A(3).test; )
Comment #2 by contact — 2020-05-24T14:00:58Z
Oh... I see ... Since this is an really old regression, I don't think it will be fixed until the next release.
Comment #3 by b2.temp — 2020-05-26T03:37:13Z
This could definitively be done for next point release.
The problem seems simple to fix. Apparently it's related to the trailing tuple template parameter `Params...`, the compiler does not accept that its length is equal to 0...I'm 90% sure it's a problem of lowering, meaning that
`A(3).test()`
is not rewritten
`A(3).opDispatch!("test")()`
properly.
Comment #4 by b2.temp — 2020-05-26T04:09:34Z
Expression semanticX(DotIdExp exp, Scope* sc)
dmd/expressionsem.d:
---
Expression semanticX(DotIdExp exp, Scope* sc)
{
+ printf("checkpoint %d : %s\n", 0, exp.toChars());
//printf("DotIdExp::semanticX(this = %p, '%s')\n", this, toChars());
if (Expression ex = unaSemantic(exp, sc))
return ex;
+ printf("checkpoint %d : %s\n", 1, exp.toChars());
...
}
---
gives, for the test case:
> checkpoint 0 : A(int(0)).test
> checkpoint 1 : ((A __slA
so unaSemantic corrupts the expression.
`__slA` is a special symbol created in dmd.expression.StructLiteralExp.addDtorHook().
So that's this method that does a bad rewrite (or maybe even a kind of corruption)
Comment #5 by dlang-bot — 2021-11-30T16:18:31Z
@RazvanN7 created dlang/dmd pull request #13374 "Fix Issue 20860 - OpDispatch does not work for structs with constructor and destructor" fixing this issue:
- Fix Issue 20860 - OpDispatch does not work for structs with constructor and destructor
https://github.com/dlang/dmd/pull/13374
Comment #6 by dlang-bot — 2021-12-01T22:43:32Z
dlang/dmd pull request #13374 "Fix Issue 20860 - OpDispatch does not work for structs with constructor and destructor" was merged into stable:
- 2029bc2b5cd71c50d4863a7fc6b3936c72d044d8 by RazvanN7:
Fix Issue 20860 - OpDispatch does not work for structs with constructor and destructor
https://github.com/dlang/dmd/pull/13374
Comment #7 by dlang-bot — 2021-12-14T10:34:11Z
dlang/dmd pull request #13421 "merge stable" was merged into master:
- 71b3c3c5c4b6b95ac32e58e0b6dd787cd03875d5 by RazvanN7:
Fix Issue 20860 - OpDispatch does not work for structs with constructor and destructor
https://github.com/dlang/dmd/pull/13421