Skip to content

Commit

Permalink
Showcase stack overflow bug with polyvariants (#851)
Browse files Browse the repository at this point in the history
* showcase stack overflow bug with polyvariants

* Mark where the stack overflow happens.

* try something

* changelog

* remove debug

---------

Co-authored-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
  • Loading branch information
zth and cristianoc authored Dec 18, 2023
1 parent e11dfe3 commit de25a65
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Proper default for `"uncurried"` in V11 projects. https://github.com/rescript-lang/rescript-vscode/pull/867
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
- Fix infinite loop when resolving inferred completions when several values in scope has the same name. https://github.com/rescript-lang/rescript-vscode/pull/869
- Fix crash when trying to print recursive polymorphic variants without a concrete definition. https://github.com/rescript-lang/rescript-vscode/pull/851

#### :nail_care: Polish

Expand Down
1 change: 1 addition & 0 deletions analysis/src/PrintType.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let printExpr ?(lineWidth = 60) typ =
Printtyp.reset_names ();
Printtyp.reset_and_mark_loops typ;
Res_doc.toString ~width:lineWidth
(Res_outcome_printer.printOutTypeDoc (Printtyp.tree_of_typexp false typ))

Expand Down
14 changes: 14 additions & 0 deletions analysis/tests/src/PolyRec.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let rec sum = x =>
switch x {
| #Leaf => 0
| #Node(value, left, right) => value + left->sum + right->sum
}

let myTree = #Node(
1,
#Node(2, #Node(4, #Leaf, #Leaf), #Node(6, #Leaf, #Leaf)),
#Node(3, #Node(5, #Leaf, #Leaf), #Node(7, #Leaf, #Leaf)),
)

let () = myTree->sum->Js.log
// ^hov
12 changes: 6 additions & 6 deletions analysis/tests/src/expected/CompletionPattern.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Path f
"label": "optThird",
"kind": 5,
"tags": [],
"detail": "optThird: option<[#second(someRecord) | #first]>\n\nsomeRecord",
"detail": "optThird: option<[#first | #second(someRecord)]>\n\nsomeRecord",
"documentation": null
}, {
"label": "nest",
Expand All @@ -150,7 +150,7 @@ Path f
"label": "optThird",
"kind": 5,
"tags": [],
"detail": "optThird: option<[#second(someRecord) | #first]>\n\nsomeRecord",
"detail": "optThird: option<[#first | #second(someRecord)]>\n\nsomeRecord",
"documentation": null
}, {
"label": "nest",
Expand Down Expand Up @@ -189,7 +189,7 @@ Path z
"label": "optThird",
"kind": 5,
"tags": [],
"detail": "optThird: option<[#second(someRecord) | #first]>\n\nsomeRecord",
"detail": "optThird: option<[#first | #second(someRecord)]>\n\nsomeRecord",
"documentation": null
}]

Expand Down Expand Up @@ -267,7 +267,7 @@ Path f
"label": "optThird",
"kind": 5,
"tags": [],
"detail": "optThird: option<[#second(someRecord) | #first]>\n\nsomeRecord",
"detail": "optThird: option<[#first | #second(someRecord)]>\n\nsomeRecord",
"documentation": null
}, {
"label": "nest",
Expand Down Expand Up @@ -360,7 +360,7 @@ Path z
"label": "optThird",
"kind": 5,
"tags": [],
"detail": "optThird: option<[#second(someRecord) | #first]>\n\nsomeRecord",
"detail": "optThird: option<[#first | #second(someRecord)]>\n\nsomeRecord",
"documentation": null
}, {
"label": "nest",
Expand Down Expand Up @@ -451,7 +451,7 @@ Path b
"label": "optThird",
"kind": 5,
"tags": [],
"detail": "optThird: option<[#second(someRecord) | #first]>\n\nsomeRecord",
"detail": "optThird: option<[#first | #second(someRecord)]>\n\nsomeRecord",
"documentation": null
}, {
"label": "nest",
Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ Hover src/Hover.res 106:21
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```"}}

Hover src/Hover.res 116:16
{"contents": {"kind": "markdown", "value": "```rescript\nAA.cond<[< #str(string)]> => AA.cond<[< #str(string)]>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"}}
{"contents": {"kind": "markdown", "value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"}}

Hover src/Hover.res 119:25
{"contents": {"kind": "markdown", "value": "```rescript\nAA.cond<[< #str(string)]> => AA.cond<[< #str(string)]>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"}}
{"contents": {"kind": "markdown", "value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"}}

Hover src/Hover.res 122:3
Nothing at that position. Now trying to use completion.
Expand Down
3 changes: 3 additions & 0 deletions analysis/tests/src/expected/PolyRec.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hover src/PolyRec.res 12:10
{"contents": {"kind": "markdown", "value": "```rescript\n([#Leaf | #Node(int, 'a, 'a)] as 'a)\n```"}}

0 comments on commit de25a65

Please sign in to comment.