Summary: Covariant return types don't work with static arrays
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Piotr Szturmaj <> 2011-10-22 09:07:48 PDT 
This is an example from, but
with changed return types:

class Foo {
  int[] test() { return null; }

class Bar : Foo {
  int[2] test() { return [1, 2]; } // overrides and is covariant with

// and here's additional test code:

void main() {
  Foo f = new Bar();
  auto arr = f.test();
  assert(arr.length == 2);

This code compiles but fails on assert. Returned arr.length is 1 and accessing
the first element of that array results in access violation.

Given that static arrays are implicitly convertible to dynamic arrays, it
should work. If not, it at least should not compile.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to