completium / archetype-lang

MIT License
70 stars 9 forks source link

Map literal not accepted within map.put method #356

Open grum-tez opened 1 year ago

grum-tez commented 1 year ago

Not sure if this is a bug or I don't understand the syntax - but compare these two things:

This is valid and compiles:

var owm: map<band, map<string, duration>> = [];
const this_duration_map: map<string, duration> = [(id, ownership_asset[id].time_held)];
owm.put(this_band, this_duration_map);      

But if I copy-paste the literal directly into the put method argument, it doesn't compile.

var owm: map<band, map<string, duration>> = [];
 owm.put(this_band, [(id, ownership_asset[id].time_held)]);

This doesn't compile and gives "No such method: 'put'" in the vs code problems readout

rognierbenoit commented 1 year ago

thanks @grum-tez , indeed the typer should be able to infer the type of the [ ] literal, which can be either list or map; because here the expected type is map. it is something we should be improving. there is a workaround with make_map builtin to force the type:

var owm: map<band, map<string, duration>> = [];
owm.put(this_band, make_map<string, duration>([(id, ownership_asset[id].time_held)]));