1 /+
2  dub.sdl:
3  name "covariant"
4  dependency "openmethods" path="../"
5  buildType "x" {
6    buildOptions "debugMode" "debugInfo" "unittests"
7    debugVersions "explain"
8  }
9 
10  buildType "xtc" {
11    buildOptions "debugMode" "debugInfo" "unittests"
12    debugVersions "explain" "traceCalls"
13  }
14  +/
15 
16 module covariant_test;
17 
18 import std.stdio;
19 
20 import openmethods;
21 mixin(registerMethods);
22 
23 class Container {
24 }
25 
26 class Bottle : Container {
27   this(string label) {
28     this.label = label;
29   }
30   string label;
31 }
32 
33 class Tool {
34 }
35 
36 class Corkscrew : Tool {
37   this(string brand) {
38     this.brand = brand;
39   }
40   string brand;
41 }
42 
43 string open(virtual!Container, covariant!Tool);
44 
45 @method
46 string _open(Bottle bottle, Corkscrew corkscrew)
47 {
48   return "open a " ~ bottle.label ~ " with a " ~ corkscrew.brand;
49 }
50 
51 void main() {
52   updateMethods;
53   Container container = new Bottle("Chateauneuf-du-Pape");
54   Tool tool = new Corkscrew("Brabantia corkscrew");
55   //writeln(open(container, tool));
56   assert(open(container, tool) == "open a Chateauneuf-du-Pape with a Brabantia corkscrew");
57 }