www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20920] New: Typedef!int + Typedef!int => int? is this a


          Issue ID: 20920
           Summary: Typedef!int + Typedef!int => int? is this a typedef
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: mingwu gmail.com

https://forum.dlang.org/post/qkxnscppciawulevjskv forum.dlang.org


import std.typecons;
import std.stdio;

alias MyInt = Typedef!int;

void f(MyInt mi) {}

void main() {
  MyInt a = 2;
  MyInt b = 3;
  f(a + b);

td.d(14,4): Error: function td.f(Typedef!(int, 0, null) mi) is not callable
using argument types (int)
td.d(14,4):        cannot pass argument a.opBinary(b) of type int to parameter
Typedef!(int, 0, null) mi

Naturally I've expected `a + b` will have the same type as MyInt (not the
underlying type int).

Is this a typedef overlook, or it's a feature by design?

If it's by design what's the reason behind?

I think this is a bug, because on the doc page, the purpose of Typedef is:

Typedef allows the creation of a unique type which is based on an existing
type. Unlike the alias feature, Typedef ensures the two types are not
considered as equals.


Jun 10 2020