diff --git a/src/modules/function/declaration.rs b/src/modules/function/declaration.rs index e25f83fd..9e9036ae 100644 --- a/src/modules/function/declaration.rs +++ b/src/modules/function/declaration.rs @@ -191,7 +191,7 @@ impl SyntaxModule for FunctionDeclaration { optional = true; let mut expr = Expr::new(); syntax(meta, &mut expr)?; - if arg_type != Type::Generic && arg_type != expr.get_type() { + if !expr.get_type().is_allowed_in(&arg_type) { return error!(meta, name_token, "Optional argument does not match annotated type"); } self.arg_optionals.push(expr); diff --git a/src/modules/types.rs b/src/modules/types.rs index 41b2bebb..825b8a1f 100644 --- a/src/modules/types.rs +++ b/src/modules/types.rs @@ -17,6 +17,7 @@ pub enum Type { impl Type { pub fn is_subset_of(&self, other: &Type) -> bool { match (self, other) { + (_, Type::Generic) => true, (Type::Array(current), Type::Array(other)) => { **current != Type::Generic && **other == Type::Generic } diff --git a/src/tests/validity/function_optional_argument_generic_array.ab b/src/tests/validity/function_optional_argument_generic_array.ab new file mode 100644 index 00000000..329af889 --- /dev/null +++ b/src/tests/validity/function_optional_argument_generic_array.ab @@ -0,0 +1,10 @@ +// Output +// Hello World +// 1 2 3 + +fun echo_var(arg: [] = [1, 2, 3]): Null { + echo arg +} + +echo_var(["Hello", "World"]) +echo_var()