Skip to content

Stack overflow when showing a type involving recursive polymorphic variants #1034

@interphx

Description

@interphx

Thanks for all the work on ReScript!

I'm running into an issue with the VS Code extension freezing when trying to view the type of fold in the following code (simplified from an actual language AST):

type ast<'a> = [
  | #Num(int)
  | #Add('a, 'a)
]

type rec expression = ast<expression>

// Hovering over "fold" freezes the language server, even with explicit signature
let rec fold = (expr: ast<'a>, transform: 'a => 'b): 'b =>
  switch expr {
  | #Num(_) as num => transform(num)
  | #Add(lhs, rhs) => transform(#Add(fold(lhs, transform), fold(rhs, transform)))
  }

The tooltip gets stuck at "Loading...", formatting the file also becomes unresponsive. After about a minute, the following error gets logged in the extension output:

Fatal error: exception Stack overflow

Fatal error: exception Stack overflow
Error: Command failed: c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\analysis_binaries\win32\rescript-editor-analysis.exe hover c:\___\rescript-stackoverflow-minimal-repro\src\Demo.res 13 12 C:\Users\___\AppData\Local\Temp\rescript_format_file_7676_27 true
Fatal error: exception Stack overflow

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at checkExecSyncError (node:child_process:928:11)
    at Object.execFileSync (node:child_process:964:15)
    at Object.func (node:electron/js2c/node_init:2:2214)
    at Lt (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:36:5435)
    at Ct (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:36:5637)
    at aw (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:42:5564)
    at process.Ph (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:42:15178)
    at process.emit (node:events:519:28) {
  status: 2,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 46 61 74 61 6c 20 65 72 72 6f 72 3a 20 65 78 63 65 70 74 69 6f 6e 20 53 74 61 63 6b 20 6f 76 65 72 66 6c 6f 77 0d 0a>
  ],
  pid: 1788,
  stdout: <Buffer >,
  stderr: <Buffer 46 61 74 61 6c 20 65 72 72 6f 72 3a 20 65 78 63 65 70 74 69 6f 6e 20 53 74 61 63 6b 20 6f 76 65 72 66 6c 6f 77 0d 0a>
}
Original response:  
Args:  [
  'hover',
  'c:\\Dev\\rescript-stackoverflow-minimal-repro\\src\\Demo.res',
  13,
  12,
  'C:\\Users\\___\\AppData\\Local\\Temp\\rescript_format_file_7676_27',
  true
]

This is purely an extension issue, the code compiles and runs just fine. The issue persists after restarting VS Code without also restarting the build process, which makes me think that it may be related to formatting, and not actual type inference.

ReScript version: 11.1.3
Extension version: v1.55.5 (pre-release, but this also happens on stable)
OS: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions