-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5895: REPL autocompletion crashes in certain cases #6414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The corner case where this solution misbehaves: opaque type T = String; val x: T = ???; x.len<TAB> The above will autocomplete to scala> object Foo {
| opaque type T = String
| val x: T = ???
| x.len<TAB> If evaluated, the behaviour is correct: scala> object Foo {
| opaque type T = String
| val x: T = ???
| x.length
| }
4 | x.length
| ^^^^^^^^
| value length is not a member of Foo.T An alternative approach would be to map the cursor position to the trees generated after desugaring and typecheck. However, FTTB it seems the cursor is oblivious to the transformations done to the input and depends only on the input string. |
Don't know what's going on but at this point we should be looking at the type of |
40bcb2c
to
82fb01e
Compare
Ok, I removed the completion part but left the crash part since it affects not only opaque types (see the test). Hope you don't mind a bit of FP inside :) I've also created an issue #6415 to log the problem with opaque types completion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
Given that we have #6415 to fix the completion itself
The crashes happen due to the fact that in certain cases, certain trees get mispositioned during code completion. E.g. this happens with `opaque type T = Int` or `object Foo { type T = Int`. The tree spans are set incorrectly because repl doesn't set the sources of these trees correctly. Precisely, when typechecking on code completion, a virtual source is used. However, when parsing for autocompletion, a line source is used which is created by the parsing logic. This commit makes sure that REPL is consistent in its source choices when computing code completions.
Crashes
The crashes happen due to the fact that in certain cases,
certain trees get mispositioned during code completion. E.g.
this happens with
opaque type T = Int
orobject Foo { type T = Int
.The tree spans are set incorrectly because repl doesn't set the
sources of these trees correctly. Precisely, when typechecking
on code completion, a virtual source is used. However, when
parsing for autocompletion, a line source is used which is
created by the parsing logic. This commit makes sure that REPL
is consistent in its source choices when computing code completions.
Completion
The above commit does not bring the code completion for opaque types, however.
REPL code completion computes completion candidates for a given
expression after typechecking it. Typechecking opaque types
desugars them from
<mods> type T = Int
to<mods> type T = T.T
.The completion relies on the position of the user's cursor
in the input expression to know what part of this expression to complete.
Since the cursor does not take the semantic info computed by typechecking,
the cursor points to
T.T
and not toInt
on completion request.Completion on synthetic
T.T
does not pick any candidates, which isunexpected to the user. The expected behavior is to complete on
Int
,the underlying type. This commit achieves the expected behavior by
making sure opaque types are treated as ordinary types on code completion.