Bug 11708 – Too much weak typing of std.typecons.Typedef

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-12-07T07:40:53Z
Last change time
2020-03-21T03:56:39Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-12-07T07:40:53Z
This code compiles and runs with no errors with dmd 2.065alpha: void main() { import std.typecons: Typedef; alias T = Typedef!int; T x; x = 10; int y = 10; x = y; T[5] arr; arr[0] = 10; } The point of using Typedef is to define a strong type, so I think assigning to it with the original type should not be allowed. And indeed the now deprecated typedef didn't allow it: void main() { typedef int T; int y = 10; T x; x = y; // line 5, error. } temp.d(5): Error: cannot implicitly convert expression (y) of type int to T
Comment #1 by b2.temp — 2017-09-15T05:38:58Z
That's very comic how Typedef can be too weak for you here but too strong there: https://issues.dlang.org/show_bug.cgi?id=11707 You have to learn what you want bearophile.