digitalmars.D.learn - Limited type matching?
- Namespace (20/20) Sep 08 2013 Code:
- Namespace (2/22) Sep 09 2013 Ok I fill a bug for that...
- Andrej Mitrovic (2/3) Sep 09 2013 Please do, that code should compile.
- Andrej Mitrovic (4/7) Sep 09 2013 Oh I didn't even noticed it was a signed/unsigned issue. I'm not sure
- monarch_dodra (10/20) Sep 09 2013 I think the "issue" is that when you write "[1, 2]", that array
- Kenji Hara (11/21) Sep 09 2013 Currently, all of array types does not allow copy-conversion like
- Namespace (3/12) Sep 10 2013 And what is your personal opinion?
- Kenji Hara (24/39) Sep 10 2013 Hmm, OK. I've taken a look a little deeper about the current
- Namespace (3/43) Sep 10 2013 Nice to hear. I already filled a bug report:
Code: ---- import std.stdio; void foo(short x, short y) { } void foo(short[2] xy) { } void main() { foo(1, 2); /// works foo([1, 2]); /// works ushort[2] xy = [1, 2]; foo(xy); /// fails ushort x = 1, y = 2; foo(x, y); /// works } ---- What is the problem? If the compiler is able to cast implicit from ushort to short, what is the problem of casting ushort[2] to short[2]?
Sep 08 2013
On Sunday, 8 September 2013 at 21:11:53 UTC, Namespace wrote:Code: ---- import std.stdio; void foo(short x, short y) { } void foo(short[2] xy) { } void main() { foo(1, 2); /// works foo([1, 2]); /// works ushort[2] xy = [1, 2]; foo(xy); /// fails ushort x = 1, y = 2; foo(x, y); /// works } ---- What is the problem? If the compiler is able to cast implicit from ushort to short, what is the problem of casting ushort[2] to short[2]?Ok I fill a bug for that...
Sep 09 2013
On 9/9/13, Namespace <rswhite4 googlemail.com> wrote:Ok I fill a bug for that...Please do, that code should compile.
Sep 09 2013
On 9/8/13, Namespace <rswhite4 googlemail.com> wrote:What is the problem? If the compiler is able to cast implicit from ushort to short, what is the problem of casting ushort[2] to short[2]?Oh I didn't even noticed it was a signed/unsigned issue. I'm not sure whether or not it's a bug. But file it anyways and someone will know what to do with it.
Sep 09 2013
On Monday, 9 September 2013 at 11:36:42 UTC, Andrej Mitrovic wrote:On 9/8/13, Namespace <rswhite4 googlemail.com> wrote:I think the "issue" is that when you write "[1, 2]", that array is still "weakly typed", and the compiler will implicitly cast it to any type that will create a match. Once you've crammed it into a variable though, it becomes explicitly typed, and the casts become no-go. It's kind of like how you can write: wstring s = "hello!"; I dare say that the behavior is expected.What is the problem? If the compiler is able to cast implicit from ushort to short, what is the problem of casting ushort[2] to short[2]?Oh I didn't even noticed it was a signed/unsigned issue. I'm not sure whether or not it's a bug. But file it anyways and someone will know what to do with it.
Sep 09 2013
On Monday, 9 September 2013 at 11:36:42 UTC, Andrej Mitrovic wrote:On 9/8/13, Namespace <rswhite4 googlemail.com> wrote:Currently, all of array types does not allow copy-conversion like ushort to short for their elements. In old D1 age, static array did not have value semantics, so the behavior was expected. In D2, static array had changed to value type, but the behavior was not changed. As far as I know, there was no discussion about that, but at least it is not fundamentally wrong. Kenji HaraWhat is the problem? If the compiler is able to cast implicit from ushort to short, what is the problem of casting ushort[2] to short[2]?Oh I didn't even noticed it was a signed/unsigned issue. I'm not sure whether or not it's a bug. But file it anyways and someone will know what to do with it.
Sep 09 2013
Currently, all of array types does not allow copy-conversion like ushort to short for their elements. In old D1 age, static array did not have value semantics, so the behavior was expected. In D2, static array had changed to value type, but the behavior was not changed. As far as I know, there was no discussion about that, but at least it is not fundamentally wrong. Kenji HaraAnd what is your personal opinion? I think an implicit cast between signed / unsigned would be acceptable even with static arrays. It were only logical.
Sep 10 2013
On Tuesday, 10 September 2013 at 08:04:48 UTC, Namespace wrote:Hmm, OK. I've taken a look a little deeper about the current behavior. void main() { void f1(short) {} void f2(short[2]) {} void f3(short[]) {} ushort us = 1; short ss = us; // OK ss = us; // OK f1(us); // OK ushort[2] usa = [1,2]; short[2] ssa = usa; // OK -> [x] ssa = usa; // NG -> [y] f2(usa); // NG -> [y] ushort[] uda = [1,2]; short[] sda = uda; // NG, expected sda = uda; // NG, expected f3(uda); // NG, expected } Surely the current state that, [x] is accepted but [y] is rejected, looks weird to me. It would be a bug. Kenji HaraCurrently, all of array types does not allow copy-conversion like ushort to short for their elements. In old D1 age, static array did not have value semantics, so the behavior was expected. In D2, static array had changed to value type, but the behavior was not changed. As far as I know, there was no discussion about that, but at least it is not fundamentally wrong. Kenji HaraAnd what is your personal opinion? I think an implicit cast between signed / unsigned would be acceptable even with static arrays. It were only logical.
Sep 10 2013
On Tuesday, 10 September 2013 at 10:53:15 UTC, Kenji Hara wrote:On Tuesday, 10 September 2013 at 08:04:48 UTC, Namespace wrote:Nice to hear. I already filled a bug report: http://d.puremagic.com/issues/show_bug.cgi?id=10999Hmm, OK. I've taken a look a little deeper about the current behavior. void main() { void f1(short) {} void f2(short[2]) {} void f3(short[]) {} ushort us = 1; short ss = us; // OK ss = us; // OK f1(us); // OK ushort[2] usa = [1,2]; short[2] ssa = usa; // OK -> [x] ssa = usa; // NG -> [y] f2(usa); // NG -> [y] ushort[] uda = [1,2]; short[] sda = uda; // NG, expected sda = uda; // NG, expected f3(uda); // NG, expected } Surely the current state that, [x] is accepted but [y] is rejected, looks weird to me. It would be a bug. Kenji HaraCurrently, all of array types does not allow copy-conversion like ushort to short for their elements. In old D1 age, static array did not have value semantics, so the behavior was expected. In D2, static array had changed to value type, but the behavior was not changed. As far as I know, there was no discussion about that, but at least it is not fundamentally wrong. Kenji HaraAnd what is your personal opinion? I think an implicit cast between signed / unsigned would be acceptable even with static arrays. It were only logical.
Sep 10 2013