Skip to content

Commit

Permalink
fix callbacks and expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
serkonda7 committed Jan 22, 2025
1 parent 9c80d57 commit 95be144
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/bait/checker/fun.bt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ fun (c Checker) fun_params(params []ast.Param){
typ = p.typ
kind = .function
pkg = c.pkg
return_type = info.return_type
params = info.to_params()
})
} else {
c.scope.register(p.name, context.ScopeObject{
Expand Down
15 changes: 12 additions & 3 deletions tests/type/fun_types_test.bt
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// SPDX-FileCopyrightText: 2023-present Lukas Neubert <[email protected]>
// SPDX-License-Identifier: MIT

// This struct has to compile
struct Foo {
fun_field fun (string) i32
}

fun test_placeholder() {
// Above code just has to compile
assert true
fun takes_callback(s string, cb fun (string) i32) i32 {
return cb(s)
}

fun my_cb(s string) i32 {
return s.length
}

fun test_callback() {
assert takes_callback("hi", my_cb) == 2
assert takes_callback("you", my_cb) == 3
}

0 comments on commit 95be144

Please sign in to comment.