Skip to content

Commit

Permalink
all: use new function type syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
serkonda7 committed Jan 29, 2025
1 parent 9b99281 commit ed4c5ab
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes are documented in this file.

## 0.0.9 - unreleased
### Breaking Changes
- Syntax: Require argument names in function type declarations ([GH-308](https://github.com/bait-lang/bait/pull/308))

### New Language Features
- Array slicing using range indexing: `arr[low..high]`

Expand Down
2 changes: 1 addition & 1 deletion docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ type NewType := ExistingType
Type aliases can also name a specific function signature:

```bait
type CheckInt := fun (i32) bool
type CheckInt := fun (i i32) bool
// You can use the alias like any other type, for example as parameter
fun check_nums(nums []i32, c CheckInt) {
Expand Down
2 changes: 1 addition & 1 deletion examples/function_types.bt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type CheckInt := fun (i32) bool
type CheckInt := fun (i i32) bool

// You can use the alias like any other type, for example as parameter
fun check_nums(nums []i32, c CheckInt) {
Expand Down
6 changes: 1 addition & 5 deletions lib/bait/parser/type.bt
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ fun (mut p Parser) parse_fun_type() !ast.Type {
p.check(.lpar)!
mut param_types := []ast.Type
for p.tok != .rpar{
if p.peek() != .rpar {
_ = p.check_name()! // Require argument name but ignore it for now
} else {
p.warn("expected argument name")
}
_ = p.check_name()! // Require argument name but ignore it for now
typ := p.parse_type()!
param_types.push(typ)
if p.tok != .rpar{
Expand Down
2 changes: 1 addition & 1 deletion lib/builtin/array.js.bt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fun (a Array) reverse_in_place() {
a.data.reverse()
}

pub fun (a Array) filter(fn fun (any) bool) Array {
pub fun (a Array) filter(fn fun (cond any) bool) Array {
return from_js_arr(a.data.filter(fn as #JS.Any))
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/cli.bt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package cli

import strings

type Callback := fun (Command)
type Callback := fun (cmd Command)

pub struct Command {
name string
Expand Down
2 changes: 1 addition & 1 deletion tests/method/struct_field_fun_test.bt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT

struct Helpers{
num_to_str fun (i32) string
num_to_str fun (i i32) string
}

fun test_struct_field_method() {
Expand Down
2 changes: 1 addition & 1 deletion tests/out/error/redef/redef.in.bt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fun foo[X](x X) {}

static MyCapName := 1
struct MyCapName{}
type MyCapName := fun (string, f64) bool
type MyCapName := fun (x string, y f64) bool
type MyCapName := []u8
type MyCapName := i8 | i16
enum MyCapName {}
4 changes: 2 additions & 2 deletions tests/type/fun_types_test.bt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

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

fun takes_callback(s string, cb fun (string) i32) i32 {
fun takes_callback(s string, cb fun (s string) i32) i32 {
return cb(s)
}

Expand Down

0 comments on commit ed4c5ab

Please sign in to comment.