Function types (#6891)

* Change Fn to fn for function types

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Support args and return types in function types

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Use fancy function types in the docs

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-05-13 14:59:23 +12:00
committed by GitHub
parent 47feae3bd9
commit 01c7b69f50
16 changed files with 209 additions and 47 deletions

View File

@ -2575,6 +2575,27 @@ sketch002 = startSketchOn({
assert_eq!(actual, input);
}
#[test]
fn recast_function_types() {
let input = r#"foo = x: fn
foo = x: fn(number)
fn foo(x: fn(): number): fn {
return 0
}
fn foo(x: fn(a, b: number(mm), c: d): number(Angle)): fn {
return 0
}
type fn
type foo = fn
type foo = fn(a: string, b: { f: fn(): any })
type foo = fn([fn])
type foo = fn(fn, f: fn(number(_))): [fn([any]): string]
"#;
let ast = crate::parsing::top_level_parse(input).unwrap();
let actual = ast.recast(&FormatOptions::new(), 0);
assert_eq!(actual, input);
}
#[test]
fn unparse_call_inside_function_args_multiple_lines() {
let input = r#"fn foo() {