tdenniston / bish

Bish is a language that compiles to Bash. It's designed to give shell scripting a more comfortable and modern feel.
MIT License
1.48k stars 36 forks source link

Compiler crash if number used as function name #19

Closed richq closed 9 years ago

richq commented 9 years ago

Here's a messed up bit of code that causes bish to segfault:

def f(n) {
    return 8(n);
}

An "invalid token type for atom" or similar error would be OK, I don't expect the code to actually work since numbers are used for argument passing in the compiled shell code.

egorsmkv commented 9 years ago

I might add that use "_" character in variable and function names can not. This is not very convenient.

richq commented 9 years ago

Yeah, but bish just doesn't like the and tells you so "Unhandled token character at character '', line 4". That seems like a different issue to me "let me use _ in variable and function names".

digitalsurgeon commented 9 years ago

in the case of:

def f(n) {
return 8(n);
}

the problem lies in Parser.cpp Parser::factor()

 IRNode *a = atom(); // a is created as integer.
        if (tokenizer->peek().isa(Token::LParenType)) {
            Variable *v = static_cast<Variable*>(a); // casting it to Variable, Name is not initialized!!
            // The symbol will be reinserted as a Function, not a Variable.
            remove_from_symbol_table(v->name);
            a = funcall(v->name); // !!! CRASH IN FUNCALL
        }

The checker pass has not run at this point and the types are all undefined.

tdenniston commented 9 years ago

@richq can you verify that it's fixed? I actually wasn't seeing a segfault on my system.

@digitalsurgeon thanks very much for tracking that down. Made fixing it trivial :-).

tdenniston commented 9 years ago

@eg0r With commit 9214bce underscores are now allowed.

egorsmkv commented 9 years ago

@tdenniston Thanks!

richq commented 9 years ago

Confirmed, no longer crashes.