mir.algebraic: Visitor cannot be called

Andre Pany andre at s-e-a-p.de
Wed Dec 9 14:34:18 UTC 2020


Hi,

I want to port some Python coding and try have as much similiar 
coding as
possible.

I thought I can have a mir variant which stores either class A or 
B
and I can call at runtime a method like this:

```
/+ dub.sdl:
	name "app"
	dependency "mir-core" version="1.1.51"
+/

import std.stdio: writeln;
import mir.algebraic;

class A {
	void foo(int i){writeln("A.foo");}
}

class B {
	void foo(int i, string s){writeln("B.foo");}
}

void main() {
	Variant!(A,B) v = new A();
	v.foo(3);
}
```

But it fails with:
Error: static assert:  "Algebraic!(A, B): the visitor cann't be 
caled with arguments (B, int)"

The error message seems strange. Is the behavior I want somehow 
possible?
(At runtime I know whether I have an object of A or B and will 
only call
with the correct method signature).

Kind regards
André


More information about the Digitalmars-d-learn mailing list