I'm encountering an error in Mata interactive sessions when I call a static class method that returns a class and try to assign the returned instance to a variable. If the method is defined outside of a class everything works fine; if it is defined as a static method of a class, I get a "type mismatch: transmorphic = class not allowed" error.
For example, if I define a basic class:
From an interactive session, if I try to capture the instance of myclass returned by myclass::create(), I get the error:
But if I define the function exactly the same except outside the class, everything works fine:
What's going on here? Am I doing something wrong?
Thanks,
Yosef
For example, if I define a basic class:
Code:
version 13.1 mata: mata set matastrict on mata set matalnum on class myclass { real scalar x void dump() static class myclass scalar create() } void myclass::dump() { printf("myclass, x:%f\n",x) } class myclass scalar myclass::create() { class myclass scalar c c.x = 9 return(c) }
Code:
a = myclass::create() /* <---- THROWS ERROR: "type mismatch: transmorphic = class not allowed" */
Code:
// exact same as myclass::create() except not defined as a static class function class myclass scalar create2() { class myclass scalar c c.x = 9 return(c) } a = create2() /* (no error) */ a.dump() /* prints "myclass, x:9" */
Thanks,
Yosef
Comment