www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9359] New: Can't concat ints: incompatible types for 'int' and 'int'

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9359

           Summary: Can't concat ints: incompatible types for 'int' and
                    'int'
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com


--- Comment #0 from Nick Sabalausky <cbkbbejeap mailinator.com> 2013-01-20
13:20:12 PST ---
void main()
{
    int a = 0;
    int[] b = a ~ a;
}
========================
test.d(4): Error: incompatible types for ((a) ~ (a)): 'int' and 'int'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9359


Nils <nilsbossung googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nilsbossung googlemail.com


--- Comment #1 from Nils <nilsbossung googlemail.com> 2013-01-20 14:20:49 PST
---
(In reply to comment #0)
 void main()
 {
     int a = 0;
     int[] b = a ~ a;
 }
 ========================
 test.d(4): Error: incompatible types for ((a) ~ (a)): 'int' and 'int'

I can't see the bug. That's not supposed/specified to work, is it? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9359


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2013-01-20 14:35:15 PST ---
Normally you do it like this:


void main() {
    int a = 0;
    int[] b = [a, a];
}


Or even:

void main() {
    int a = 0;
    int[] b = (int[]).init ~ a ~ a;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9359


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
            Version|unspecified                 |D2
         Resolution|                            |INVALID


--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2013-01-20
14:39:42 PST ---
ints are not arrays, and can't be concatenated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9359



--- Comment #4 from Nick Sabalausky <cbkbbejeap mailinator.com> 2013-01-21
16:17:43 PST ---
They can be concatenated with arrays, thus producing another array.

But thinking about it more, defining 'int~int' to result in 'int[]' would be
inconsistent with the fact that 'int[]~int[]' results in 'int[]' instead of
'int[][]'.

This does result in some annoying inconsistencies:

int[] a = [1] ~  1  ~  1;  // OK
int[] a =  1  ~ [1] ~  1;  // OK
int[] a =  1  ~  1  ~ [1]; // Fail

int[] a = [1] ~ [1]; // OK
int[] a =  1  ~ [1]; // OK
int[] a = [1] ~  1;  // OK
int[] a =  1  ~  1;  // Fail

But I guess I don't see a way around that without introducing the more
error-prone inconsistency of:

[[1]] ~ [[1]]  --> int[][]
 [1]  ~  [1]   --> int[]
  1   ~   1    --> int[]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 21 2013