nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
122 stars 27 forks source link

Return types give an error #140

Closed petrisch closed 2 weeks ago

petrisch commented 2 weeks ago

In this project I am trying to use return type annotations. Which in this minimal case give a error:

def foo [
    test: string 
    ] nothing -> string {
         $test
}
foo bla

My best guess is, that in this line the return sequence is defined with a colon, which maybe should be a thin_arrow: https://github.com/nushell/tree-sitter-nu/blob/7e0f16f608a9e804fae61430ade734f9f849fb80/grammar.js#L148

blindFS commented 2 weeks ago

It's fixed in this commit, but it may take long before merged.

For now, you can add colon before the return type:

def foo [
    test: string 
    ]: nothing -> string { # <-----
         $test
}
foo bla
fdncred commented 2 weeks ago

Correct, we might should just close this and not fix it in tree-sitter-nu because improper syntax should show errors, right?

def foo [test: string]: nothing -> string { $test }
                      ^
                      |___ Nushell is supposed to require this colon. It is a bug in nushell that an error isn't thrown.
petrisch commented 2 weeks ago

@fdncred oh there is supposed to be a colon there, gosh I didn't consider that at all. Makes totally sense, and yes this is not TS-nu's fault then 😄

fdncred commented 2 weeks ago

@petrisch right. the problem is that nushell doesn't currently enforce the colon to be there, but it should. that's a bug in nushell.