mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-30 15:11:45 +00:00
Infer function expressions in matching contexts (#514)
* legalizes omitting types on function expressions within function type contexts * legalizes omitting any number of arguments
This commit is contained in:
src
std/assembly
tests
compiler.js
compiler
builtins.optimized.watbuiltins.untouched.watfunction-expression.optimized.watfunction-expression.tsfunction-expression.untouched.watfunction-types.optimized.watfunction-types.untouched.watgetter-call.optimized.watgetter-call.untouched.watinlining.optimized.watinlining.untouched.wat
std
parser
@ -14,3 +14,23 @@ f3();
|
||||
|
||||
var f4 = (): i32 => 1;
|
||||
assert(f4() == 1);
|
||||
|
||||
function testOmitted(fn: (a: i32, b: i32) => i32): i32 {
|
||||
return fn(1, 2);
|
||||
}
|
||||
assert(testOmitted((a, b) => a + b) == 3);
|
||||
assert(testOmitted(a => a) == 1);
|
||||
assert(testOmitted(() => 42) == 42);
|
||||
|
||||
function testOmittedReturn1(): (a: i32, b: i32) => i32 {
|
||||
return (a, b) => a + b;
|
||||
}
|
||||
function testOmittedReturn2(): (a: i32, b: i32) => i32 {
|
||||
return a => a;
|
||||
}
|
||||
function testOmittedReturn3(): (a: i32, b: i32) => i32 {
|
||||
return () => 42;
|
||||
}
|
||||
assert(testOmittedReturn1()(1, 2) == 3);
|
||||
assert(testOmittedReturn2()(1, 2) == 1);
|
||||
assert(testOmittedReturn3()(1, 2) == 42);
|
||||
|
Reference in New Issue
Block a user