vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

typedef does not handle constructors correctly #408

Open charlesstaats opened 6 months ago

charlesstaats commented 6 months ago

For example, there is a struct in three.asy called Render that has a void operator init() constructor in which all parameters have default values. Thus,

import three;
render();

runs successfully without error. However, if we then do

typedef render Render;
Render();

an error results.

For completeness, here's what I actually ran in interactive mode to test this (the only line that produced an error was Render()):

> import three
> render()
> typedef render Render;
> Render()
-: 1.1: no matching variable 'Render'
> Render f() { return render(); }
> f()  // no error for returning something of type Render
> 

As a side note, it might make sense for typedef to duplicate the names of functions whose name is the same as the return type, whether or not those functions are constructors. For instance, it might make sense for the following code

struct a { int x; }

a a(int x) {
  a retv = new a;
  retv.x = x;
  return retv;
}

typedef a b;

to include syntactic sugar for something like b b(int) = a;.