Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid VM instruction when setting routine as part of a tuple. #545

Open
IngwiePhoenix opened this issue Dec 22, 2018 · 1 comment
Open

Comments

@IngwiePhoenix
Copy link

(dao) tup2 = ( cb = routine() {}, 'abc' )
[[ERROR]] in file "interactive codes":
  At line 0 : Invalid function definition --- " __main__() ";
  At line 1 : Invalid virtual machine instruction --- " SETVG:4,2,0 ";
In code snippet:
      4 :  TUPLE       :     2 ,     2 ,     4 ;     1;   ( cb = routine() {}, 'ab...'...
>>    5 :  SETVG       :     4 ,     2 ,     0 ;     1;   tup2
      6 :  RETURN      :     4 ,     1 ,     0 ;     1;   )
  At line 1 : Invalid operation on the type --- " tup2 ";
  At line 1 : Types not matching --- " 'tuple<cb:routine<=>none>,string>' for 'tuple<index:int,string>' ";

I just tried this out for fun. Well, this is what comes out.

@dumblob
Copy link

dumblob commented Apr 12, 2019

This is clearly a type error - last line says it explicitly. tup2 was apparently already initialized (last line says that the original type was tuple<index:int,string>, i.e. something like var tup2 = ( index=5, "str00" ).

By default in Dao once variable has a type, you can't change the type any more. If you wanted to change the type (or part of it), you would need to use explicit runtime (i.e. dynamic) typing for which the word any is reserved - e.g. var x: any = (0, "a"); x = (routine(){}, "b") or better (safer) var x: tuple<any, string> = (0, "a"); x = (routine(){}, "b"). But beware, runtime typing can't be checked in advance (in compile time), so it opens another pandora box of programming mistakes and it's also slower than static typing 😉.

By the way make use of invar instead of var (especially in all interfaces) as it helps to reveal not negligible amount of subtle bugs and has a noticeable positive impact on the programming style 😉 (among other things using read-only or copy-on-write views when interfacing with non-Dao libraries and code allows for significant safety and usually also performance gains).

Hope this clarifies the typing in Dao a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants