[Issue 9112] Uniform construction for built-in types

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 6 19:47:20 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #23 from bearophile_hugs at eml.cc 2013-11-24 05:41:58 PST ---
(In reply to comment #21)

> void main()
> {
>     alias Call!(GetFunc!()) square;
>     square(2);  // actually calls int(2)
> }
> 
> test.d(13): Error: function expected before (), not int of type int
> 
> With the pull this becomes valid code.
> 
> Maybe it's obvious in this case, but when you combine tuples, mixins, etc, it
> could be hard to notice what's wrong. The way I see it, the more the line
> between functions and types becomes blurred the harder it can be to track bugs.

This code gives:

void main() {
    cast(int)2;
}


temp.d(2): Error: long has no effect in expression (2)


So I think this will give a similar error message:

void main() {
    int(2);
}


On the other hand this probably will not give an error:

...
void main() {
    alias Call!(GetFunc!()) square;
    auto n = square(2);
}


cast(...) is a dangerous tool, so it's a good idea to introduce a feature like
int(...) that avoids some usages of cast(...). T(x) where T is a built-in type
is a little safer than a cast because it gives errors when the conversion is
not possible.

So I think the advantages here could outweigh the risks.

--- Comment #24 from github-bugzilla at puremagic.com 2014-03-06 19:47:10 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0ddf824ff02c181ac9b8b4fc9abc843a1e3cc6f1
fix Issue 9112 - Uniform construction for built-in types

Support syntax T(), T(v), and new T(v) for basic type T

https://github.com/D-Programming-Language/dmd/commit/17917a2be2929e33fefbca3384a23521b2ff65f0
Merge pull request #1356 from 9rnsr/uniform_ctor

Issue 9112 - Uniform construction for built-in types

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


More information about the Digitalmars-d-bugs mailing list