jshell: better unresolved symbol handling

This commit is contained in:
Max Weber
2021-07-16 19:07:34 -06:00
committed by Abex
parent ac7aa18147
commit fc208853a4

View File

@@ -55,6 +55,7 @@ import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Segment;
import jdk.jshell.DeclarationSnippet;
import jdk.jshell.Diag;
import jdk.jshell.JShell;
import jdk.jshell.Snippet;
@@ -315,11 +316,13 @@ public abstract class ShellPanel extends JPanel
{
Snippet snip = ev.snippet();
offsets.put("#" + snip.id(), thisOffset);
if (ev.status() != Snippet.Status.VALID && ev.status() != Snippet.Status.RECOVERABLE_DEFINED)
if (ev.status() != Snippet.Status.VALID)
{
boolean handled = false;
var diags = shell.diagnostics(snip).collect(Collectors.toList());
for (var diag : diags)
{
handled = true;
String msg = toStringDiagnostic(src, thisOffset, diag);
if (isUserCode)
{
@@ -331,11 +334,23 @@ public abstract class ShellPanel extends JPanel
throw new RuntimeException("prelude error: " + msg);
}
}
if (diags.isEmpty())
if (snip instanceof DeclarationSnippet)
{
var unresolved = shell.unresolvedDependencies((DeclarationSnippet) snip).collect(Collectors.toList());
for (var ident : unresolved)
{
handled = true;
logToConsole("Unresolved symbol: " + ident);
}
}
if (!handled)
{
logToConsole("bad snippet" + ev.status());
}
break evaluation;
if (ev.status() != Snippet.Status.RECOVERABLE_DEFINED)
{
break evaluation;
}
}
if (ev.exception() != null)
{