diff --git a/CHANGELOG.md b/CHANGELOG.md index dab1057f5..9a981e20e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/analysis/src/PrintType.ml b/analysis/src/PrintType.ml index f06239f60..3fe104398 100644 --- a/analysis/src/PrintType.ml +++ b/analysis/src/PrintType.ml @@ -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)) diff --git a/analysis/tests/src/PolyRec.res b/analysis/tests/src/PolyRec.res new file mode 100644 index 000000000..c2fdbdf52 --- /dev/null +++ b/analysis/tests/src/PolyRec.res @@ -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 diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index 56f0ad0f9..850c64919 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -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", @@ -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", @@ -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 }] @@ -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", @@ -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", @@ -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", diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 8503e0b48..9fdad7048 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -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. diff --git a/analysis/tests/src/expected/PolyRec.res.txt b/analysis/tests/src/expected/PolyRec.res.txt new file mode 100644 index 000000000..64c790174 --- /dev/null +++ b/analysis/tests/src/expected/PolyRec.res.txt @@ -0,0 +1,3 @@ +Hover src/PolyRec.res 12:10 +{"contents": {"kind": "markdown", "value": "```rescript\n([#Leaf | #Node(int, 'a, 'a)] as 'a)\n```"}} +