www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DIP-1000 and return

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
The code


auto asStatic(T, size_t length)(T[length] arr)
{
     return arr;
}

 safe pure nothrow  nogc unittest
{
     auto x = [1, 2, 3].asStatic;
     static assert(is(typeof(x) == int[x.length]));
     static assert(is(typeof([1, 2, 3].asStatic) == 
int[x.length]));
}


now fails on Git master (after DIP-1000 has been merged) as


array_ex.d(55,6): Error: parameter arr is 'return' but function 
does not return any indirections
array_ex.d(63,23): Error: template instance 
array_ex.asStatic!(int, 3LU) error instantiating
array_ex.d(64,5): Error: static assert  (is(typeof(x) == 
int[x.length])) is false


I tried qualifying argument with `return ref` as described at

https://wiki.dlang.org/DIP25

but that fails because parameter must be allowed to be an r-value 
aswell.

Any clues?
Jan 01
next sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Sunday, 1 January 2017 at 17:41:46 UTC, Nordlöw wrote:
 The code


 auto asStatic(T, size_t length)(T[length] arr)
 {
     return arr;
 }

  safe pure nothrow  nogc unittest
 {
     auto x = [1, 2, 3].asStatic;
     static assert(is(typeof(x) == int[x.length]));
     static assert(is(typeof([1, 2, 3].asStatic) == 
 int[x.length]));
 }


 now fails on Git master (after DIP-1000 has been merged) as


 array_ex.d(55,6): Error: parameter arr is 'return' but function 
 does not return any indirections
 array_ex.d(63,23): Error: template instance 
 array_ex.asStatic!(int, 3LU) error instantiating
 array_ex.d(64,5): Error: static assert  (is(typeof(x) == 
 int[x.length])) is false


 I tried qualifying argument with `return ref` as described at

 https://wiki.dlang.org/DIP25

 but that fails because parameter must be allowed to be an 
 r-value aswell.

 Any clues?
Try: auto asStatic(T, size_t length)(scope T[length] arr) { return arr; }
Jan 01
next sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Sunday, 1 January 2017 at 18:00:54 UTC, Stefan Koch wrote:
 Try:
  auto asStatic(T, size_t length)(scope T[length] arr)
  {
      return arr;
  }
Fails as array_ex.d(72,10): Error: parameter arr is 'return' but function does not return any indirections array_ex.d(80,27): Error: template instance array_ex.asStatic!(int, 3LU) error instantiating array_ex.d(81,9): Error: static assert (is(typeof(x) == int[x.length])) is false
Jan 01
prev sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Sunday, 1 January 2017 at 18:00:54 UTC, Stefan Koch wrote:

 Try:
  auto asStatic(T, size_t length)(scope T[length] arr)
  {
      return arr;
  }
I've tried as many combinations of `return` and `scope` as I can think of such as T[length] asStatic(T, size_t length)(return scope T[length] arr) { return arr; } but all complain about the same thing Error: parameter arr is 'return' but function does not return any indirections It seems like compiler incorrectly infers that `arr` must be `return` despite it doesn't have any indirections (because it's a static array). Walter?
Jan 02
parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 2 January 2017 at 14:38:53 UTC, Nordlöw wrote:
 I've tried as many combinations of `return` and `scope` as I 
 can think of such as
Update: Qualifying `asStatic` with ` safe pure nothrow nogc` as T[length] asStatic(T, size_t length)(T[length] arr) safe pure nothrow nogc { return arr; } makes safe pure nothrow nogc unittest { auto x = [1, 2, 3].asStatic; static assert(is(typeof(x) == int[x.length])); static assert(is(typeof([1, 2, 3].asStatic) == int[x.length])); } compile. Also T[length] asStatic(T, size_t length)(scope T[length] arr) safe pure nothrow nogc { return arr; } works. Is with or without `scope` preferred here? Seems to be some problem with template qualifier inference. Should I file a bug report?
Jan 02
parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
On Monday, 2 January 2017 at 15:28:57 UTC, Nordlöw wrote:

 Should I file a bug report?
Yes please
Mar 08
prev sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Sunday, 1 January 2017 at 17:41:46 UTC, Nordlöw wrote:
 now fails on Git master (after DIP-1000 has been merged) as
When compiled with `-transition=safe`, that is.
Jan 01