Skip to content

Commit 83547f5

Browse files
committed
Fix nested/qualified modules and add tests
1 parent 0ba2bde commit 83547f5

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

source/openmethods.d

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,10 @@ auto removeStorageClasses(rf.Parameter[] parameters)
461461
return parameters.map!(p => p.withStorageClasses([])).array;
462462
}
463463

464-
struct Method(alias module_, string name, int index)
464+
struct Method(string module_, string name, int index)
465465
{
466-
alias Module = module_;
466+
mixin("static import ", module_, ";");
467+
alias Module = mixin(module_);
467468
enum Name = name;
468469
enum Index = index;
469470

@@ -582,11 +583,11 @@ struct Method(alias module_, string name, int index)
582583
.mixture);
583584

584585
enum aliases = q{
585-
alias %s = openmethods.Method!(%s, "%s", %d).dispatcher;
586-
alias %s = openmethods.Method!(%s, "%s", %d).discriminator;
586+
alias %s = openmethods.Method!("%s", "%s", %d).dispatcher;
587+
alias %s = openmethods.Method!("%s", "%s", %d).discriminator;
587588
}.format(
588-
Name, __traits(identifier, Module), Name, Index,
589-
Name, __traits(identifier, Module), Name, Index);
589+
Name, module_, Name, Index,
590+
Name, module_, Name, Index);
590591

591592
// ==========================================================================
592593
// Method Registration
@@ -779,7 +780,7 @@ unittest
779780
static assert(!hasVirtualParameters!nonmeth);
780781
}
781782

782-
string registrationMixture(alias MODULE, alias moduleName)()
783+
string registrationMixture(alias MODULE, string moduleName)()
783784
{
784785
import std.array;
785786

@@ -789,7 +790,7 @@ string registrationMixture(alias MODULE, alias moduleName)()
789790
static if (is(typeof(__traits(getOverloads, MODULE, m)))) {
790791
foreach (i, o; __traits(getOverloads, MODULE, m)) {
791792
static if (hasVirtualParameters!(o)) {
792-
mixture ~= openmethods.Method!(MODULE, m, i).aliases;
793+
mixture ~= openmethods.Method!(moduleName, m, i).aliases;
793794
}
794795
}
795796
}
@@ -804,7 +805,7 @@ string registrationMixture(alias MODULE, alias moduleName)()
804805
return join(mixture, "\n");
805806
}
806807

807-
mixin template registrar(alias MODULE, alias ModuleName)
808+
mixin template registrar(alias MODULE, string ModuleName)
808809
{
809810
import openmethods;
810811
import std.traits;
@@ -815,7 +816,7 @@ mixin template registrar(alias MODULE, alias ModuleName)
815816
static if (is(typeof(__traits(getOverloads, MODULE, m)))) {
816817
foreach (i, o; __traits(getOverloads, MODULE, m)) {
817818
static if (hasVirtualParameters!(o)) {
818-
openmethods.Method!(MODULE, m, i).register;
819+
openmethods.Method!(ModuleName, m, i).register;
819820
}
820821
}
821822
}

tests/source/qualified.mod.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module qualified.mod;
2+
3+
import openmethods;
4+
mixin(registerMethods);
5+
6+
interface Node {}
7+
8+
void walkNode(virtual!Node);
9+
10+
@method
11+
void _walkNode(Node node)
12+
{
13+
// Dummy
14+
}

0 commit comments

Comments
 (0)