View mode: basic / threaded / horizontal-split · Log in · Help
July 10, 2012
[Issue 8374] New: One missed array literal interpretation as int[2]
http://d.puremagic.com/issues/show_bug.cgi?id=8374

          Summary: One missed array literal interpretation as int[2]
          Product: D
          Version: D2
         Platform: x86
       OS/Version: Windows
           Status: NEW
         Keywords: rejects-valid
         Severity: normal
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2012-07-10 15:18:42 PDT ---
I am not sure, but I think this code is correct:


struct Foo {
   int[2] bar;
}
const(int[2]) spam() {
   const Foo* x;
   return true ? x.bar : [10, 20];
}
void main() {}


But DMD 2.060alpha gives:

test.d(6): Error: cannot implicitly convert expression
(cast(const(int)[])(*x).bar) of type const(int)[] to const(int[2u])

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 10, 2012
[Issue 8374] One missed array literal interpretation as int[2]
http://d.puremagic.com/issues/show_bug.cgi?id=8374


Walter Bright <bugzilla@digitalmars.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|NEW                         |RESOLVED
                CC|                            |bugzilla@digitalmars.com
        Resolution|                            |INVALID


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2012-07-10 16:36:56 PDT ---
The type of

  [1,2]

is int[], not int[2].

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 10, 2012
[Issue 8374] One missed array literal interpretation as int[2]
http://d.puremagic.com/issues/show_bug.cgi?id=8374


timon.gehr@gmx.ch changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|RESOLVED                    |REOPENED
                CC|                            |timon.gehr@gmx.ch
        Resolution|INVALID                     |


--- Comment #2 from timon.gehr@gmx.ch 2012-07-10 16:56:28 PDT ---
The [1,2] / [10,20] literal implicitly converts to int[2].
It is similar to the following:

struct Foo{
   short bar;
}

short spam() {
   const Foo* x;
   return true ? x.bar : 1;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 11, 2012
[Issue 8374] One missed array literal interpretation as int[2]
http://d.puremagic.com/issues/show_bug.cgi?id=8374



--- Comment #3 from bearophile_hugs@eml.cc 2012-07-10 17:49:56 PDT ---
(In reply to comment #1)
> The type of
> 
>    [1,2]
> 
> is int[], not int[2].

Usually in my bug reports I add some cases where the code works, to avoid
troubles like this one.


This works:


struct Foo {
   int[2] bar;
}
int[2] spam() {
   Foo* x;
   return true ? x.bar : [10, 20];
}
void main() {}


This too works:


struct Foo {
   int[2] bar;
}
const(int[2]) spam() {
   const Foo* x;
   const(int[2]) r = true ? x.bar : [10, 20];
   return r;
}
void main() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 16, 2013
[Issue 8374] One missed array literal interpretation as int[2]
http://d.puremagic.com/issues/show_bug.cgi?id=8374


yebblies <yebblies@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |yebblies@gmail.com


--- Comment #4 from yebblies <yebblies@gmail.com> 2013-01-17 02:22:44 EST ---
Is this the same as issue 8277?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home