diff options
| author | Marmare314 <49279081+Marmare314@users.noreply.github.com> | 2023-04-13 16:07:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 16:07:58 +0200 |
| commit | 0105eb7382801b56781308ea94b3aeffa6fd867f (patch) | |
| tree | 9374989fb8999f4d1ca1362c8b96679cc61be9e0 /tests | |
| parent | d1cd814ef8149cbac6e59c81e074aa59c930eed3 (diff) | |
Fix function sinks (#638)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/typ/compiler/closure.typ | 4 | ||||
| -rw-r--r-- | tests/typ/compiler/spread.typ | 34 |
2 files changed, 36 insertions, 2 deletions
diff --git a/tests/typ/compiler/closure.typ b/tests/typ/compiler/closure.typ index bdd8a549..a1e51d56 100644 --- a/tests/typ/compiler/closure.typ +++ b/tests/typ/compiler/closure.typ @@ -156,6 +156,10 @@ #let f(a, b, a: none, b: none, c, b) = none --- +// Error: 13-14 duplicate parameter +#let f(a, ..a) = none + +--- // Error: 7-17 expected identifier, named pair or argument sink, found keyed pair #((a, "named": b) => none) diff --git a/tests/typ/compiler/spread.typ b/tests/typ/compiler/spread.typ index 690e8931..1bfef7b0 100644 --- a/tests/typ/compiler/spread.typ +++ b/tests/typ/compiler/spread.typ @@ -27,7 +27,7 @@ #{ let save(..args) = { test(type(args), "arguments") - test(repr(args), "(1, 2, three: true)") + test(repr(args), "(three: true, 1, 2)") } save(1, 2, three: true) @@ -56,6 +56,11 @@ #f(..for x in () []) --- +// unnamed spread +#let f(.., a) = a +#test(f(1, 2, 3), 3) + +--- // Error: 13-19 cannot spread string #calc.min(.."nope") @@ -64,7 +69,7 @@ #let f(..true) = none --- -// Error: 15-16 only one argument sink is allowed +// Error: 13-16 only one argument sink is allowed #let f(..a, ..b) = none --- @@ -91,3 +96,28 @@ --- // Error: 5-11 cannot spread array into dictionary #(..(1, 2), a: 1) + +--- +// Spread at beginning. +#{ + let f(..a, b) = (a, b) + test(repr(f(1)), "((), 1)") + test(repr(f(1, 2, 3)), "((1, 2), 3)") + test(repr(f(1, 2, 3, 4, 5)), "((1, 2, 3, 4), 5)") +} + +--- +// Spread in the middle. +#{ + let f(a, ..b, c) = (a, b, c) + test(repr(f(1, 2)), "(1, (), 2)") + test(repr(f(1, 2, 3, 4, 5)), "(1, (2, 3, 4), 5)") +} + +--- +#{ + let f(..a, b, c, d) = none + + // Error: 4-10 missing argument: d + f(1, 2) +} |
