aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions.bad
blob: 3149a24987bedfc181f237d02b9bc02690284bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
; Simple function declarations don't need a block.
fun add_two(a: int, b: int): int a + b

; Functions return the result of the last expression implicitly.
fun add_three(a: int, b: int, c: int): int {
    add_two(a, b) + c
}

; Functions that don't return anything must explicitly state it as returning
; nil.
fun foo(): nil {
    println("hello buddy")
}

; An alternate form for empty return values.
fun bar(): () {
    foo()
}

; We support multiple return values, in this case the "return" keyword must be
; explict.
fun baz(a: int, b: str): (int, str) {
    return(1, "hello")
}

; Make sure we can use pointer types on params and return values.
fun test(a: @int[256], b: @str): @int {
    a
}