diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a1573e..7e53a03d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]` diff --git a/examples/function_types.bt b/examples/function_types.bt index dbedd1f1..bcfdf7e8 100644 --- a/examples/function_types.bt +++ b/examples/function_types.bt @@ -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) { diff --git a/lib/bait/parser/type.bt b/lib/bait/parser/type.bt index 9cce46f9..9c9fdafc 100644 --- a/lib/bait/parser/type.bt +++ b/lib/bait/parser/type.bt @@ -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{ diff --git a/lib/builtin/array.js.bt b/lib/builtin/array.js.bt index 4f82bfd1..5167c571 100644 --- a/lib/builtin/array.js.bt +++ b/lib/builtin/array.js.bt @@ -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)) } diff --git a/lib/cli/cli.bt b/lib/cli/cli.bt index 98d36c13..d01ca74f 100644 --- a/lib/cli/cli.bt +++ b/lib/cli/cli.bt @@ -4,7 +4,7 @@ package cli import strings -type Callback := fun (Command) +type Callback := fun (cmd Command) pub struct Command { name string diff --git a/tests/method/struct_field_fun_test.bt b/tests/method/struct_field_fun_test.bt index 6c0fdd6b..898f0e0c 100644 --- a/tests/method/struct_field_fun_test.bt +++ b/tests/method/struct_field_fun_test.bt @@ -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() { diff --git a/tests/out/error/redef/redef.in.bt b/tests/out/error/redef/redef.in.bt index 2b272f2e..82cf014f 100644 --- a/tests/out/error/redef/redef.in.bt +++ b/tests/out/error/redef/redef.in.bt @@ -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 {} diff --git a/tests/type/fun_types_test.bt b/tests/type/fun_types_test.bt index b020475d..025274be 100644 --- a/tests/type/fun_types_test.bt +++ b/tests/type/fun_types_test.bt @@ -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) }