[Issue 22010] Link error with mutually recursive SumType / struct with opEquals
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 9 12:08:08 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22010
João Lourenço <jlourenco5691 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jlourenco5691 at gmail.com
--- Comment #1 from João Lourenço <jlourenco5691 at gmail.com> ---
I think this is because it uses `match` internally. You are passing a `const
Ref!T` in your `opEquals` which makes its `TagTuple` a `const(TagTuple)`. When
trying to match it won't be able to.
As a workaround fix, removing `const` from `opEquals` solves your issue.
Also, refactoring your `opEquals` to a template (to allow the program to
compile), gives a more propper error when comparing the types:
```d
/+dub.sdl:
dependency "sumtype" version="~>1.1.1"
+/
import sumtype;
struct S { Ref!Node node; }
alias Node = SumType!S;
private struct Ref(T)
{
private T* _ref_ptr;
this(ref T value) { _ref_ptr = &value; } ///
bool opEquals()(ref const Ref!T other) { return *_ref_ptr ==
*other._ref_ptr; }
}
void main()
{
S s;
assert(S.init == s);
}
```
Produces (tested with sumtype-1.1.1):
---
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(1718,13): Error: need `this`
for `tags` of type `ulong[2]`
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(1718,13): Error: need `this`
for `tags` of type `ulong[2]`
Error: `this` for `__invariant430` needs to be type `TagTuple` not type
`const(TagTuple)`
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(1828,4): Error: static
assert: "`handlers[0]` of type `template` never matches"
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(1448,46): instantiated
from here: `matchImpl!(const(SumType!(S)), const(SumType!(S)))`
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(578,31): instantiated
from here: `match!(const(SumType!(S)), const(SumType!(S)))`
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(587,11): instantiated
from here: `opEquals!(const(SumType!(S)), const(SumType!(S)))`
onlineapp.d(14,53): instantiated from here: `opEquals!(SumType!(S),
const(SumType!(S)))`
onlineapp.d(10,9): instantiated from here: `opEquals!()`
dmd failed with exit code 1.
---
This should work though.
--
More information about the Digitalmars-d-bugs
mailing list