dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.56k stars 1.44k forks source link

Check for semantic errors with scalac #815

Open dlion opened 7 years ago

dlion commented 7 years ago

I have a prova.scala file with an error:

object Hi {
    def main(args: Array[String]) = {
        var capital = Map("US" -> "Washington", "France" -> "Paris")
        capitall += ("Japan" -> "Tokyo")
        println(capital)
    }
}

and I have installed scalac (using brew) scalac -version Scala compiler version 2.12.3 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.

but ale doesn't work, here the result of ALEInfo:

 Current Filetype: scala
Available Linters: ['scalac', 'scalastyle']
  Enabled Linters: ['scalac', 'scalastyle']
 Linter Variables:
let g:ale_scala_scalastyle_options = ''
 Global Variables:
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%s'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'always'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_open_list = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_offset = 1000000
let g:ale_sign_warning = '--'
let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK']
let g:ale_warn_about_trailing_whitespace = 1
  Command History:
(finished - exit code 0) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/8/prova.scala''']
<<<NO OUTPUT RETURNED>>>
(finished - exit code 0) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/9/prova.scala''']
<<<NO OUTPUT RETURNED>>>
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/10/prova.scala''']
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/11/prova.scala''']
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/12/prova.scala''']
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/13/prova.scala''']
(finished - exit code 0) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/14/prova.scala''']
<<<NO OUTPUT RETURNED>>>
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/15/prova.scala''']
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/16/prova.scala''']
(started) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/17/prova.scala''']
(finished - exit code 0) ['/bin/zsh', '-c', '''scalac'' -Ystop-after:parser ''/var/folders/00/wrh2b2x919j89j1pv9m_d2kh0000gn/T/nvimjqQM7P/18/prova.scala''']
<<<NO OUTPUT RETURNED>>>

As you can see <<<NO OUTPUT RETURNED>>>, I tried to reproduce this error from the shell and scalac is not return any errors so I tried without -Ystop-after:parser parameter and it works fine:

~/p/s/m/scala scalac prova.scala
prova.scala:4: error: not found: value capitall
    capitall += ("Japan" -> "Tokyo")
    ^
one error found

and with the -Ystop-after:parser parameter

 ~/p/s/m/scala scalac -Ystop-after:parser prova.scala

so is the parameter the problem?

Thanks

w0rp commented 7 years ago

At the moment, the scalac linter only checks syntax, it doesn't do any semantic analysis. I'll rename this issue to a request for semantic analysis.

w0rp commented 7 years ago

Checking for semantic errors might be easier to implement now work has been done for the javac linter to look for dependencies with maven and gradle.