Basic support for for (var/k, v in X) syntax#431
Basic support for for (var/k, v in X) syntax#431SpaceManiac merged 8 commits intoSpaceManiac:masterfrom
for (var/k, v in X) syntax#431Conversation
|
Wouldn't the type of k (if it's not a primitive) be derived from the ss13 syntax of |
ZeWaka
left a comment
There was a problem hiding this comment.
Also, don't we have tests? Why put your test cases in the description if you're not going to put in as tests?
|
I agree with the var_type thing - however DM will not let you give a var type to v in the Thinking about it I should create a I didnt notice the parser had unit tests. I am more than happy to include the |
|
I've added a basic unit test that shows a I've also added a block : // the "v" in a DM for (var/k, v) statement is essentially typeless.
// There is currently no way to change that.
let var_type_value = VarType {
flags: VarTypeFlags::from_bits_truncate(0),
type_path: Box::new([]),
input_type: InputType::from_bits_truncate(0),
};DM lets you type |
|
this is fine for now |
What this does
This add a new arm to the parser for the
for (var/k, v in X)dict-like syntax that was added in 516.How this works
I have hijacked the arm that checks for this type of expressions :
for (init, test, inc)orfor (init; test; inc)I have seperated it between
init; test; inc(left untouched) andinit, test, inc.If
incis not None, I then check iftestin aBinaryOp::In(something likefor(init, [x in y]). If not I just assume it's afor (init, test)which is valid DM syntax.I then check if
initis avar/ktype of statement, using copypaste. DM will not compilefor (k, v)nor will it compilefor (var/k, var/v).I check if v is an ident.
If we're all good, I create a new type of structure
ForKeyValueStatementand the lib.rs / findreferences.rs knows what to do with it.Cases tested :
See unit tests in the Files Changed
✅
❌ "for (var/key, value) requires a 'var' keyword"
❌ "cannot assigned a value in var/key for(var/key, value) statement"
❌ "path has no effect" (was already covered)
❌ "value must be a variable in for (var/key, value) statement"
Regression checks
Both
for (i = 0, i < 10, i++),for (i = 0, i < 10)still pass.