Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Fix error reporting when parsing an lident #448

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ let rec parseLident p =
loop p
end
in
Parser.err p (Diagnostics.lident p.Parser.token);
Parser.next p;
loop p;
match p.Parser.token with
Expand Down
14 changes: 13 additions & 1 deletion tests/parsing/errors/expressions/expected/letBinding.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,21 @@

This let-binding misses an expression


Syntax error!
tests/parsing/errors/expressions/letBinding.res:15:12

13 │ }
14 │
15 │ let foo as 'x = ()
16 │

I'm expecting a lowercase name like `user or `age`

let foo = 2.
let foo = true
let foo = 2
let foo = f ()
let foo = ((2)[@ns.braces ])
let foo = (("foo")[@ns.braces ])
let foo = (("foo")[@ns.braces ])
let foo as x = ()
1 change: 1 addition & 0 deletions tests/parsing/errors/expressions/letBinding.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ let foo = == {
"foo"
}

let foo as 'x = ()
18 changes: 16 additions & 2 deletions tests/parsing/errors/other/expected/labelledParameters.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

1 │ let f = (x, y=2, z) => x + y + z
2 │
3 │ type f = (x: int, y: int) => int
3 │ let g = (~?x, ~y=2, ~z) => x + y + z

A labeled parameter starts with a `~`. Did you mean: `~y`?

Expand All @@ -14,10 +14,24 @@

1 │ let f = (x, y=2, z) => x + y + z
2 │
3 │ type f = (x: int, y: int) => int
3 │ let g = (~?x, ~y=2, ~z) => x + y + z
4 │
5 │ type f = (x: int, y: int) => int

I'm expecting a lowercase name like `user or `age`


Syntax error!
tests/parsing/errors/other/labelledParameters.res:5:11

3 │ let g = (~?x, ~y=2, ~z) => x + y + z
4 │
5 │ type f = (x: int, y: int) => int
6 │

A labeled parameter starts with a `~`. Did you mean: `~x`?

let f x ?(y= 2) z = (x + y) + z
let g ~x:((x)[@ns.namedArgLoc ]) ?y:(((y)[@ns.namedArgLoc ])= 2)
~z:((z)[@ns.namedArgLoc ]) = (x + y) + z
type nonrec f = x:int -> y:int -> int
2 changes: 2 additions & 0 deletions tests/parsing/errors/other/labelledParameters.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let f = (x, y=2, z) => x + y + z

let g = (~?x, ~y=2, ~z) => x + y + z

type f = (x: int, y: int) => int
2 changes: 1 addition & 1 deletion tests/printer/comments/pattern.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let /* before */ 123 /* after */ = 123
// Ppat_interval of constant * constant

// Ppat_alias
let /* before pat */ p /* after pat */ as /* before alias */ 'x /* after alias */ = ()
let /* before pat */ p /* after pat */ as /* before alias */ x /* after alias */ = ()
let /*c0 */ (/* c1 */ p /* c2 */ as /* c3 */x /* c4*/) as /* c5 */ y /* c6 */ = ()

// Ppat_array
Expand Down