Why does not UFCS work for method defined inside unittest block?

Ky-Anh Huynh saigon at example.net
Tue Jul 31 08:28:01 UTC 2018


Hi,

Can I define a new quick function to use inside a unittest block?

I have the following code:

[code]
auto foo(string[] sta) {
   return sta;
}

auto bar(string[] sta) {
   return sta;
}

auto h(string[] sta) {
   return sta.foo.bar;
}

unittest {
   import std.format;

   auto f = (string[] sta) => sta.foo.bar;
   auto g(string[] sta) {
     return sta.foo.bar;
   }

   assert(f(["test"]) == ["test"]);
   assert(g(["test"]) == ["test"]);
   assert(["test"].h == ["test"]);
   assert(["test"].g == ["test"]);
}
[/code]

(Src: 
https://gist.github.com/icy/64ec1838929d448d9f874d1e8261e56a)

The last test will fail: Error: no property g for type string[]

Please advise.

Thanks a lot.





More information about the Digitalmars-d-learn mailing list