D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19010 - new fails on dynamic array aliases
Summary: new fails on dynamic array aliases
Status: RESOLVED DUPLICATE of issue 20422
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-21 00:36 UTC by elpenguino+D
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description elpenguino+D 2018-06-21 00:36:22 UTC
Pretty simple example:
```
unittest {
    alias T = int[];
    T t = new T;
}
```

This doesn't seem to have ever compiled correctly. It currently fails with the misleading error "Error: new can only create structs, dynamic arrays or class objects, not int[]'s"
Comment 1 ag0aep6g 2018-06-21 16:04:14 UTC
The alias has nothing to do with the error. This gives the same error:

----
unittest {
    int[] t = new int[]; /* Error: new can only create structs, dynamic arrays or class objects, not int[]'s */
}
----

(In reply to elpenguino+D from comment #0)
> This doesn't seem to have ever compiled correctly.

As far as I know, `new int[]` is not supposed to compile. The spec [1] is a bit scarce on this, but `new`ing arrays is only mentioned with explicit lengths.


[1] https://dlang.org/spec/expression.html#new_expressions
Comment 2 basile-z 2018-06-21 16:28:04 UTC
Grammartically it's valid (it's the first new rule, i.e `new AllocatorArgumentsopt Type`) but since `new` for arrays doesn't return a pointer to an array, allowing this would be a bit pointless because

  `int[] a = new int[];`

would be the same as

  `int[] a;`
Comment 3 basile-z 2019-12-12 19:39:18 UTC
The problem is actually a bad diagnostic. This is like 20422, i.e the length parameter misses.

*** This issue has been marked as a duplicate of issue 20422 ***