Skip to content

Commit

Permalink
fix(parse,e2e): Allow 'function' as an argument type (#185)
Browse files Browse the repository at this point in the history
I'd accidentally allowed "as callable" (the internal name for a
BrightScript function) insntead of "as function".

fixes #177
  • Loading branch information
sjbarag committed Mar 1, 2019
1 parent 795efae commit e9c7701
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/brsTypes/BrsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export namespace ValueKind {
case "longinteger": return ValueKind.Int64;
case "float": return ValueKind.Float;
case "double": return ValueKind.Double;
case "callable": return ValueKind.Callable;
case "function": return ValueKind.Callable;
case "dynamic": return ValueKind.Dynamic;
case "void": return ValueKind.Void;
case "<uninitialized>": return ValueKind.Uninitialized;
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/resources/function/expressions.brs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a()
print "immediately-invoked function expression (IIFE)"
end sub)()

function acceptsCallback(initial as integer, cb)
function acceptsCallback(initial as integer, cb as function)
print "pre-callback"
cb(initial * 2)
print "post-callback"
Expand Down
4 changes: 4 additions & 0 deletions test/parser/expression/Function.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ describe("parser", () => {
identifier("count"),
identifier("as"),
identifier("integer"),
token(Lexeme.Comma, ","),
identifier("cb"),
identifier("as"),
token(Lexeme.Function, "function"),
token(Lexeme.RightParen, ")"),
token(Lexeme.Newline, "\\n"),
token(Lexeme.EndFunction, "end sub"),
Expand Down
43 changes: 43 additions & 0 deletions test/parser/expression/__snapshots__/Function.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,49 @@ Array [
},
},
},
Object {
"defaultValue": undefined,
"location": Object {
"end": Object {
"column": -9,
"line": -9,
},
"file": undefined,
"start": Object {
"column": -9,
"line": -9,
},
},
"name": Object {
"isReserved": false,
"kind": 29,
"literal": undefined,
"location": Object {
"end": Object {
"column": -9,
"line": -9,
},
"start": Object {
"column": -9,
"line": -9,
},
},
"text": "cb",
},
"type": Object {
"kind": 7,
"location": Object {
"end": Object {
"column": -9,
"line": -9,
},
"start": Object {
"column": -9,
"line": -9,
},
},
},
},
],
"returns": 9,
},
Expand Down

0 comments on commit e9c7701

Please sign in to comment.