Handle warnings, and add a warning if a function parameter has an unknown type
This commit is contained in:
parent
14e30d0855
commit
7ee230e20c
|
@ -46,6 +46,7 @@ namespace Upsilon.Binder
|
||||||
foreach (var valueParameter in unboundFunctionStatement.Value.Parameters)
|
foreach (var valueParameter in unboundFunctionStatement.Value.Parameters)
|
||||||
{
|
{
|
||||||
Scope.AssignToNearest(valueParameter.VariableSymbol);
|
Scope.AssignToNearest(valueParameter.VariableSymbol);
|
||||||
|
_diagnostics.LogUnknownVariableType(valueParameter.VariableSymbol.Name, valueParameter.Span);
|
||||||
}
|
}
|
||||||
unboundFunctionStatement.Value.Block =
|
unboundFunctionStatement.Value.Block =
|
||||||
(BoundBlockStatement) BindBlockStatement(unboundFunctionStatement.Value.UnboundBlock);
|
(BoundBlockStatement) BindBlockStatement(unboundFunctionStatement.Value.UnboundBlock);
|
||||||
|
|
|
@ -9,7 +9,8 @@ namespace Upsilon
|
||||||
public class Diagnostics
|
public class Diagnostics
|
||||||
{
|
{
|
||||||
public SourceText ScriptString { get; }
|
public SourceText ScriptString { get; }
|
||||||
public readonly List<DiagnosticsMessage> Messages = new List<DiagnosticsMessage>();
|
public readonly List<DiagnosticsMessage> Errors = new List<DiagnosticsMessage>();
|
||||||
|
public readonly List<DiagnosticsMessage> Warnings = new List<DiagnosticsMessage>();
|
||||||
public bool ThrowsOnError { get; }
|
public bool ThrowsOnError { get; }
|
||||||
|
|
||||||
public Diagnostics(SourceText scriptString, bool throwsOnError)
|
public Diagnostics(SourceText scriptString, bool throwsOnError)
|
||||||
|
@ -20,7 +21,10 @@ namespace Upsilon
|
||||||
|
|
||||||
public void Log(DiagnosticLevel level, string message, TextSpan location)
|
public void Log(DiagnosticLevel level, string message, TextSpan location)
|
||||||
{
|
{
|
||||||
Messages.Add(new DiagnosticsMessage(this, level, message, location));
|
if (level == DiagnosticLevel.Error)
|
||||||
|
Errors.Add(new DiagnosticsMessage(this, level, message, location));
|
||||||
|
else if (level == DiagnosticLevel.Warning)
|
||||||
|
Warnings.Add(new DiagnosticsMessage(this, level, message, location));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LogError(string message, TextSpan location)
|
public void LogError(string message, TextSpan location)
|
||||||
|
@ -34,6 +38,11 @@ namespace Upsilon
|
||||||
Log(DiagnosticLevel.Error, message, location);
|
Log(DiagnosticLevel.Error, message, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LogWarning(string message, TextSpan location)
|
||||||
|
{
|
||||||
|
Log(DiagnosticLevel.Warning, message, location);
|
||||||
|
}
|
||||||
|
|
||||||
public void LogBadCharacter(TextSpan location, SyntaxKind expectedToken, SyntaxKind currentKind)
|
public void LogBadCharacter(TextSpan location, SyntaxKind expectedToken, SyntaxKind currentKind)
|
||||||
{
|
{
|
||||||
LogError($"Invalid character found. Expected: '{expectedToken}', Got: '{currentKind}'", location);
|
LogError($"Invalid character found. Expected: '{expectedToken}', Got: '{currentKind}'", location);
|
||||||
|
@ -87,18 +96,25 @@ namespace Upsilon
|
||||||
{
|
{
|
||||||
LogError($"Cannot index type '{expressionType}' with type '{indexType}'", span);
|
LogError($"Cannot index type '{expressionType}' with type '{indexType}'", span);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LogUnknownVariableType(string variableName, TextSpan span)
|
||||||
|
{
|
||||||
|
LogWarning(
|
||||||
|
$"Variable '{variableName}' has an unknown variable type, and as such errors won't be visible before evaluation.",
|
||||||
|
span);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DiagnosticsMessage
|
public class DiagnosticsMessage
|
||||||
{
|
{
|
||||||
public Diagnostics Diagnostics { get; }
|
public Diagnostics Diagnostics { get; }
|
||||||
private readonly DiagnosticLevel _diagnosticLevel;
|
public DiagnosticLevel DiagnosticLevel { get; }
|
||||||
public string Message { get; }
|
public string Message { get; }
|
||||||
public TextSpan Span { get; }
|
public TextSpan Span { get; }
|
||||||
|
|
||||||
public DiagnosticsMessage(Diagnostics diagnostics, DiagnosticLevel diagnosticLevel, string message, TextSpan span)
|
public DiagnosticsMessage(Diagnostics diagnostics, DiagnosticLevel diagnosticLevel, string message, TextSpan span)
|
||||||
{
|
{
|
||||||
_diagnosticLevel = diagnosticLevel;
|
DiagnosticLevel = diagnosticLevel;
|
||||||
Diagnostics = diagnostics;
|
Diagnostics = diagnostics;
|
||||||
Message = message;
|
Message = message;
|
||||||
Span = span;
|
Span = span;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
using Upsilon.Binder;
|
using Upsilon.Binder;
|
||||||
|
|
|
@ -27,13 +27,13 @@ namespace Ycicle
|
||||||
? Executor.ParseInput(input, options)
|
? Executor.ParseInput(input, options)
|
||||||
: Executor.ContinueWith(script, input);
|
: Executor.ContinueWith(script, input);
|
||||||
|
|
||||||
if (script.Diagnostics.Messages.Count > 0)
|
if (script.Diagnostics.Errors.Count > 0)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine("Errors were found during parsing");
|
Console.WriteLine("Errors were found during parsing");
|
||||||
foreach (var diagnosticsMessage in script.Diagnostics.Messages)
|
foreach (var diagnosticsMessage in script.Diagnostics.Errors)
|
||||||
{
|
{
|
||||||
LogError(diagnosticsMessage);
|
LogMessage(DiagnosticLevel.Error, diagnosticsMessage);
|
||||||
}
|
}
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
continue;
|
continue;
|
||||||
|
@ -41,18 +41,24 @@ namespace Ycicle
|
||||||
//Console.WriteLine(script.PrettyPrintSyntaxTree());
|
//Console.WriteLine(script.PrettyPrintSyntaxTree());
|
||||||
var evaluate = script.Evaluate();
|
var evaluate = script.Evaluate();
|
||||||
|
|
||||||
if (script.Diagnostics.Messages.Count > 0)
|
if (script.Diagnostics.Errors.Count > 0)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine("Errors were found during evaluating");
|
Console.WriteLine("Errors were found during evaluating");
|
||||||
foreach (var diagnosticsMessage in script.Diagnostics.Messages)
|
foreach (var diagnosticsMessage in script.Diagnostics.Errors)
|
||||||
{
|
{
|
||||||
LogError(diagnosticsMessage);
|
LogMessage(DiagnosticLevel.Error, diagnosticsMessage);
|
||||||
}
|
}
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
foreach (var diagnosticsMessage in script.Diagnostics.Warnings)
|
||||||
|
{
|
||||||
|
LogMessage(DiagnosticLevel.Warning, diagnosticsMessage);
|
||||||
|
}
|
||||||
|
Console.ResetColor();
|
||||||
|
|
||||||
if (evaluate == null)
|
if (evaluate == null)
|
||||||
continue;
|
continue;
|
||||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
@ -63,16 +69,24 @@ namespace Ycicle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LogError(DiagnosticsMessage message)
|
private static void LogMessage(DiagnosticLevel level, DiagnosticsMessage message)
|
||||||
{
|
{
|
||||||
|
if (level == DiagnosticLevel.Error)
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
else if (level == DiagnosticLevel.Warning)
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||||
|
|
||||||
Console.WriteLine(message.Message);
|
Console.WriteLine(message.Message);
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Console.Write(message.GetDiagnosticPosition() + " ");
|
Console.Write(message.GetDiagnosticPosition() + " ");
|
||||||
Console.Write(message.LineBeforeError());
|
Console.Write(message.LineBeforeError());
|
||||||
|
|
||||||
|
if (level == DiagnosticLevel.Error)
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
else if (level == DiagnosticLevel.Warning)
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||||
|
|
||||||
Console.Write(message.AtError());
|
Console.Write(message.AtError());
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
Loading…
Reference in New Issue