Skip to content

Commit

Permalink
Make sure @:action is a void-returning function
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinresol committed Mar 23, 2021
1 parent 37557c3 commit d270caf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/coconut/storybook/Storybook.macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,26 @@ class Storybook {
case m:
m[0].pos.error('Multiple @:control meta is not supported');
}


function checkActionType() {
switch f.type {
case TFun(_, _.getID() => 'Void'): // ok
case _: f.pos.error('@:action field should be a void-returning function');
}
}

switch f.meta.extract(':action') {
case []:
// skip
case [{params: []}]:
checkActionType();
addArgType(macro {action: $v{f.name}});
case [{params: [e = {expr: EConst(CString(v))}]}]:
checkActionType();
addArgType(macro {action: $e});
case [v]:
v.pos.error('@:action meta should have at most string literal parameter');
v.pos.error('@:action meta should have at most one string literal parameter');
case m:
m[0].pos.error('Multiple @:action meta is not supported');
}
Expand Down

0 comments on commit d270caf

Please sign in to comment.