[Issue 11206] static array can be implicitly built from items, when nested in aggregate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 9 13:03:49 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11206



--- Comment #4 from monarchdodra at gmail.com 2013-10-09 13:03:47 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> > I'm arguing that AGG should not be constructible taking a 1.
> 
> That's clear, but if you want to break the language you need to consider
> writing to newsgroup. Silent language change based on some issue in bugzilla is
> evil.

Filing it in buzilla is the first step.

> > > Integer literal is a valid
> > > initializer for static array. Statement "AGG!S ts1 = AGG!S(1);" is rejected
> > > because (unfortunately) 1 is not convertible to struct.
> > 
> > Yes, integer is a valid initializer for a static array, and it is also a valid
> > initializer for a struct that holds an int.
> 
> Right.
> 
> > 
> > However, 1 is not convertible to a struct, 
> 
> Right. It is sad fact but in this context it is irrelevant because in the
> example there is no conversion from 1 to struct, there is struct literal with
> partial initializer which match initializer for first field.
> 
> > not is it convertible to a static array.
> 
> Wrong. int[1] ai = 1; ai = 1; is fine with the language so far. However in this
> case we speak about struct initializer so having integer literal to be
> initializer for static integer array is sufficient.

That doesn't mean convertible. It just means constructible and assignable:
struct S
{
    this(int);
    void opAssign(int);
}
S s = 1; s = 1;

Does that mean int is convertible to S? it doesn't.

Also:
is(int : int[1]); //FALSE

Also:
void foo(int[1]);
void main()
{
    foo(1); //HERE
}
Error: function foo (int[1]) is not callable using argument types (int)

> > AGG(1) should not compile, because 1 is not convertible to
> > typeof(AGG.tupleof[0]);
> 
> Please refer to the spec or argue if spec is incomplete for a particular case.
> Making up rules is not good. Adressing your point - this is incorrect because
> typeof(AGG.tupleof[0]) has type int[1] and initializaing or assigning 1 to
> int[1] is legal in D. I deliberatly unwrapped all templates to show that you
> are effectivelly protesting against int[1] = 1; 

I will indeed lookup the exact spec. Please let me sleep on it. Do they make
any mention about special behavior for static arrays?

> > What's happening is an implicit *construction* of a static array, in a context
> > where implicit construction is not allowed.
> 
> This is not the case. Here is struct literal with partial list of initializers
> which match respective type initializers which is fine as far D is concern.

Except the type "int" doesn't match nor is convertible to the type "int[1]"

int[1] *can* be *initialized* from an int, yes. But so can a struct. Yet doing
the same for a struct that is both constructible and assignable doesn't work
(as I believe the spec says it shouldn't).

> If
> you are complaining because this breaks some assumption of a brilliant phobos
> ideom, this should be mentioned explicitly so some solution without damaging
> language can be found (personally I object to break the language for the sake
> of writing cute template in phobos).  

That's definitely not the reason. However, that piece of code "shows" that
static arrays get a special treatment, that I do not believe they should get.

> Please don't reopen issue: CLOSED->REOPENED->CLOSED war is not good either.

Works for me if you agree to rebuke my points and prove me wrong :)

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


More information about the Digitalmars-d-bugs mailing list