ark-lang / ark

A compiled systems programming language written in Go using the LLVM framework
https://ark-lang.github.io/
MIT License
677 stars 47 forks source link

Inferrence problem #678

Closed MovingtoMars closed 8 years ago

MovingtoMars commented 8 years ago
#use std::io
#use std::unicode::utf8

test_strings := []string{
    "hello",
    "Test string 1234\n",
    "こんにちは",
    "東京",
    "你好",
    "weiß",
    "ЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя",
    "❤️ 💔 💌 💕 💞 💓 💗 💖 💘 💝 💟 💜 💛 💚 💙",
    "1;DROP TABLE users",
    "울란바토르",
    "゚・✿ヾ╲(。◕‿◕。)╱✿・゚",
};

[unused] test_string_num_runes := []uint{
    5,
    17,
    5,
    2,
    2,
    4,
    79,
    30,
    18,
    5,
    16,
};

pub func main() -> int {
    mut i: uint = 0;
    for i < len(test_strings) {
        io::printUint(i);
        io::print(": ");

        num_runes := utf8::num_runes([]u8(test_strings[i]));
        io::printUint(num_runes);
        if num_runes != test_string_num_runes[i] {
            io::print(" wrong");
            return 1;
        }

        io::println("");

        i += 1;
    }

    return 0;
}

Error:

error: [utf8:38:9] Cannot assign expression of type `$37` to variable of type `func([]u8) -> $37`
        num_runes := utf8::num_runes([]u8(test_strings[i]));
        ^
MovingtoMars commented 8 years ago

I think it has something to do with the variable having the same name as the function we're calling. Changing the variable name stops the error.

kiljacken commented 8 years ago

It's a case of utf8::num_runes not being turned into a FunctionAccess and instead being a VariableAccess. I agree that this is most likely to do with the variable name.