tags 890294 + fixed-upstream
thanks

> Hello! Following piece of code is meant to create wrapper structures
> around primitive types, simplifying creation of generic code.

I attach the answer of upstream - he has fixed the code to give a better
error message, and also gives a way to produce a working code.

Thanks

Norbert

--
PREINING Norbert                               http://www.preining.info
Accelia Inc.     +    JAIST     +    TeX Live     +    Debian Developer
GPG: 0x860CDC13   fp: F7D8 A928 26E3 16A1 9FA0 ACF0 6CAC A448 860C DC13
--- Begin Message ---
Hi Norbert,

Thanks for sending on this interesting example. On my system this causes an 
assert. I have fixed this in  
commit fc0cc036f6b3733fba8b43bf5068b009fddb6bdc to generate a more informative 
error:

/u/bowman/camp/test76.asy: 5.35: cannot convert 'real' to 'int' in assignment
/u/bowman/camp/test76.asy: 6.32: cannot cast 'Aint' to 'Areal'

The problem is that the quote code does not get re-evaluated with the new 
typedefs, but this is easy to fix with two nested evals:

`void define_wrapper(string type)
{
  string wrapper="A"+type;
  eval("var casts=quote {"+
       "public struct "+wrapper+"{ "+type+" value; };"
       "typedef "+wrapper+" TWrap;"+
       "typedef "+type+" TInner;"+
       "public TWrap operator cast(TInner value) {
          var obj=new TWrap;
          obj.value=value;
          return obj;
        }
        public TInner operator cast(TWrap obj) {
        return obj.value;
        }
     };
  eval(casts,true);",true);
}

define_wrapper("int");
define_wrapper("real");

Aint x;
Areal y;

x.value=1;
y.value=pi;

write(x.value);
write(y.value);
`

-- 
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/vectorgraphics/asymptote/issues/59#issuecomment-366422581

--- End Message ---

Reply via email to