Bug 8649 – Not accepted "const ref Type" in foreach
Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-13T04:12:00Z
Last change time
2012-09-16T04:53:49Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-09-13T04:12:08Z
void foo(ref const int x) {} // OK
void bar(const ref int x) {} // OK
void main() {
foreach (ref const int x; [1, 2, 3]) {} // OK
foreach (const ref int x; [1, 2, 3]) {} // error
}
DMD 2.061alpha gives:
test.d(5): Error: basic type expected, not ref
test.d(5): Error: no identifier for declarator const(int)
test.d(5): Error: found 'ref' when expecting ';'
test.d(5): Error: found 'x' when expecting '.' following int
test.d(5): Error: found ';' when expecting identifier following 'int.'
Comment #1 by k.hara.pg — 2012-09-13T04:29:38Z
This is a dup of issue 4090.
Comment #2 by bearophile_hugs — 2012-09-13T04:55:51Z
(In reply to comment #1)
> This is a dup of issue 4090.
At first sight it doesn't look like the same issue, because here I am listing all the types and modifiers. "const ref int" is refused, while "ref const int" is accepted. In both cases no type inferencing is required.
While in issue 4090 I put "const ref" so some type inferencing was required.
In the end if you think it's the same issue feel free to close this issue as a duplicated. Thank you.
Comment #3 by k.hara.pg — 2012-09-16T04:53:49Z
(In reply to comment #2)
> (In reply to comment #1)
> > This is a dup of issue 4090.
>
> At first sight it doesn't look like the same issue, because here I am listing
> all the types and modifiers. "const ref int" is refused, while "ref const int"
> is accepted. In both cases no type inferencing is required.
>
> While in issue 4090 I put "const ref" so some type inferencing was required.
>
> In the end if you think it's the same issue feel free to close this issue as a
> duplicated. Thank you.
As I explained in the issue, it's current grammar limitation, and it doesn't matter whether a type inference is required.
So I'll change this to 'resolved duplicated'.
*** This issue has been marked as a duplicate of issue 4090 ***