use bufio;
use fmt;
use os;
use strings;
export fn main() void = {
const user = askname();
greet(user);
};
// Asks the user to provide their name.
fn askname() str = {
fmt::println("Hello! Please enter your name:")!;
const name = bufio::scanline(os::stdin)! as []u8;
return strings::fromutf8(name)!;
};
// Greets a user by name.
fn greet(user: str) void = {
fmt::printfln("Hello, {}!", user)!;
};
--
[dima@DESKTOP-19AN2NV hare]$ hare run app.ha
Error /mnt/d/code/hare/app.ha:15:40: Cannot use error propagation on
non-tagged type str
Error /mnt/d/code/hare/app.ha:15:15: Return value void is not
assignable to function result type str
Error /mnt/d/code/hare/app.ha:12:20: Result value void is not
assignable to function result type str
Error: harec: exited with status 1
/snap/hare/17/usr/bin/hare run: build failed
On Mon Jun 12, 2023 at 3:30 PM BST, Dmitry B wrote:
-%<-
> // Asks the user to provide their name.
> fn askname() str = {
> fmt::println("Hello! Please enter your name:")!;
> const name = bufio::scanline(os::stdin)! as []u8;
> return strings::fromutf8(name)!;
-%<-
> [dima@DESKTOP-19AN2NV hare]$ hare run app.ha
> Error /mnt/d/code/hare/app.ha:15:40: Cannot use error propagation on
> non-tagged type str
You are likely using an old version of Hare, whose strings::fromutf8()
function has a different return type.
See commit 045f30961 from Wed Sep 28 16:01:20 2022 -0400
https://git.sr.ht/~sircmpwn/hare/commit/045f309618a09c836b54662ee1bcf8239b365f61
Update Hare.