Skip to content

Don't check the unfinished expression before dot as the whole expression - #14718

Merged
psfinaki merged 11 commits into
dotnet:mainfrom
auduchinok:tc-mkSynDotMissing
Feb 16, 2023
Merged

Don't check the unfinished expression before dot as the whole expression#14718
psfinaki merged 11 commits into
dotnet:mainfrom
auduchinok:tc-mkSynDotMissing

Conversation

@auduchinok

@auduchinokauduchinok commented Feb 8, 2023

Copy link
Copy Markdown
Member

A test PR to check what breaks with this change.

Consider an unfinished expression with a dot at the end: x.. In many cases the dot would be ignored and only x expression would be checked. It has bad consequences where the type of x is unified with the type that is expected in the context, despite it's an inner expression in another unfinished one:

letf x =iftruethen
x. // `x` is inferred to have type `unit`, which is not expected

That unexpected unit type breaks completion for cases where x should infer to have some other type, like string here:

letg(s:string)=()letf1 x =iftruethen// user wants to type `Length`,// but there's no completion, since `x` is mistakenly considered `unit`
x. // an error about `unit` not being compatible with `string`
g x
// the same issues:letf2 x =
x. // trying to use `x` members from code completion
g x

With this change both cases work as expected (i.e. x doesn't have any constraints in the first case and code completion suggests string members in the second one).

Another case is applying an argument:

letg(i:int)=()leth(s:string)=()letf x =
g x. // `x` is inferred to `int` instead of `string`
h x // an error

@auduchinok
auduchinok requested a review from a team as a code ownerFebruary 8, 2023 17:23
@auduchinok

auduchinok commented Feb 9, 2023

Copy link
Copy Markdown
MemberAuthor

I've removed a few other related cases that prevented a good type checker recovery.

Before, the right side is ignored:

Screenshot 2023-02-09 at 10 20 27

After, the right side is type checked with the unknown type of the missing expression after dot:

Screenshot 2023-02-09 at 10 21 09

@auduchinok

Copy link
Copy Markdown
MemberAuthor

Please merge #14739 first, and I'll update the tests here afterwards.

@psfinaki

Copy link
Copy Markdown
Contributor

@auduchinok there you go :)

@auduchinok

Copy link
Copy Markdown
MemberAuthor

@psfinaki Thanks!

I've updated parser tests for unfinished expressions (A., A.B.) and added more tests for various incomplete record field cases (the parsing got broken there in the initial implementation, and only Code Completion tests caught it).

It's ready now.

Comment threadsrc/Compiler/SyntaxTree/SyntaxTreeOps.fs
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants

@auduchinok@psfinaki@abonie@T-Gro@vzarytovskii