checker/parser: anon fn call & return type fix
parent
4b8ed3f831
commit
3ca4f5fada
|
@ -1361,6 +1361,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
|||
return table.string_type
|
||||
}
|
||||
ast.AnonFn {
|
||||
c.fn_return_type = it.decl.return_type
|
||||
c.stmts(it.decl.stmts)
|
||||
return it.typ
|
||||
}
|
||||
|
|
|
@ -622,7 +622,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||
name_w_mod := p.prepend_mod(name)
|
||||
// type cast. TODO: finish
|
||||
// if name in table.builtin_type_names {
|
||||
if (name in p.table.type_idxs || name_w_mod in p.table.type_idxs) && !(name in ['C.stat',
|
||||
if !known_var && (name in p.table.type_idxs || name_w_mod in p.table.type_idxs) && !(name in ['C.stat',
|
||||
'C.sigaction'
|
||||
]) {
|
||||
// TODO handle C.stat()
|
||||
|
|
|
@ -104,7 +104,8 @@ fn test_mut_ptr() {
|
|||
}
|
||||
|
||||
fn high_fn(f fn(int) int) {
|
||||
|
||||
x := f(111)
|
||||
println('x == $x')
|
||||
}
|
||||
|
||||
fn high_fn_no_ret(f fn(int)) {
|
||||
|
@ -132,19 +133,19 @@ fn test_anon_fn() {
|
|||
f1 := fn(a int){
|
||||
println('hello from f1')
|
||||
}
|
||||
|
||||
f1(1)
|
||||
f2 := fn(a int){
|
||||
|
||||
f2 := fn(a int) int {
|
||||
println('hello from f2')
|
||||
return 10
|
||||
}
|
||||
f2res := f2(1)
|
||||
println('f2res == $f2res')
|
||||
// assert f2res == 10
|
||||
|
||||
f2(1)
|
||||
|
||||
// TODO: fix return
|
||||
// high_fn(fn (x int) int {
|
||||
// println('hello')
|
||||
// return x + 1
|
||||
// })
|
||||
high_fn(fn (x int) int {
|
||||
return x + 1
|
||||
})
|
||||
|
||||
high_fn_no_ret(fn (x int) {
|
||||
println('hello $x')
|
||||
|
|
Loading…
Reference in New Issue