plasma icon indicating copy to clipboard operation
plasma copied to clipboard

Type error reported on wrong line.

Open PaulBone opened this issue 4 years ago • 0 comments

func string_to_int(s : String) -> Int {
    func loop(pos : StringPos, num : Int) -> Int {
        var maybe_cp = strpos_next(pos)
        match (maybe_cp) {
            None -> {
                // End of input.
                return num
            }
            Some(var cp) -> {
                var maybe_digit = codepoint_to_digit(cp)
                match (maybe_digit) {
                    Some(var digit) -> {
                        return loop(strpos_forward(pos), num * 10 + digit)
                    }
                    None -> {
                        // Could make this function return a maybe.
                        Builtin.die!("Bad number")
                        return 0
                    }
                }
            }
        }
    }
    return loop(string_begin(s))
}

The error should have been reported on the call to loop, not the creation.

PaulBone avatar Dec 01 '21 13:12 PaulBone