D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13112 - Ignore constness when copying dynamic array argument to static array parameter
Summary: Ignore constness when copying dynamic array argument to static array parameter
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-07-12 17:34 UTC by Vladimir Panteleev
Modified: 2020-08-04 04:16 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 Vladimir Panteleev 2014-07-12 17:34:42 UTC
void f(char[1] arr) {}

void main()
{
	string s;
	f(s);
}

This program currently doesn't compile:

test.d(6): Error: function test.f (char[1] arr) is not callable using argument types (string)

However, the conversion is safe, because a copy is implicitly created during dynamic->static conversion, and the array type (char) has no indirections.

Note that this limitation only seems to apply to function parameters, as the following works fine:

string s; char[1] arr = s;
Comment 1 Mathias LANG 2020-08-04 04:16:13 UTC
The problem is not constness, but that dynamic arrays do not convert implicitly to static array (which IMO is not an issue).
The difference you're seeing with variables is because initializer are treated differently. I would say that this behavior is more likely to be the issue than not having implicit conversion from static to dynamic array.
The following compiles (but obviously triggers a range error):
```
void f(char[1] arr) {}

void main()
{
	string s;
	f(s[0 .. 1]);
}
```

So closing as invalid.